Im writing some code that reads a dicom file (jpeg baseline) and Im getting a failure in my code - a dead stop actually.
Im trying to use the image decompressors with dcm4che 5.21.0 (also tried 5.22.0). But I am having problems (at least I think that's problem) configuring the java opencv libraries and dlls.
I get the debug trace coming out as
....
DEBUG DicomImageReader - Decompressor: org.dcm4che3.opencv.NativeImageReader
DEBUG DicomImageReader - Start decompressing frame #1
Mar 30, 2020 12:30:32 PM org.opencv.osgi.OpenCVNativeLoader init
INFO: Successfully loaded OpenCV native library.
where it stops dead, it dies here :
java.lang.NoSuchMethodError: org.opencv.imgcodecs.Imgcodecs.dicomJpgMatRead(Lorg/opencv/core/Mat;II)Lorg/opencv/core/Mat;
at org.dcm4che3.opencv.NativeImageReader.getNativeImage(NativeImageReader.java:287)
at org.dcm4che3.opencv.NativeImageReader.read(NativeImageReader.java:251)
at org.dcm4che3.imageio.plugins.dcm.DicomImageReader.read(DicomImageReader.java:464)
I believe I have the correct java.library.path configured, pointing to the correct library (on my windows 10 system that is C:\bin\dcm4che\dcm4che-5.21.0\lib\win-x86_64) with the correct native dll (opencv_java.dll).
I was getting a different error when setting the path incorrectly.
This is my code, pretty simple :
public byte[] getCompressedImageBytes(DicomInputStream dicomStream, int index) throws IOException {
byte[] imageBytes = null;
if (dicomStream != null) {
Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
if (iter != null) {
DicomImageReader reader = (DicomImageReader) iter.next();
try {
reader.setInput(dicomStream);
ImageReadParam params = reader.getDefaultReadParam();
// ....DIES IN HERE...
java.awt.image.BufferedImage bi = reader.read(index, params);
reader.dispose();
imageBytes = ((DataBufferByte) bi.getData().getDataBuffer()).getData();
} catch ( Exception e ) {
String msg = "Error ! Exception thrown getting imageBytes : " + e.getMessage();
logger.error( msg );
throw new IOException ( msg );
} finally {
reader.dispose();
}
}
else {
String msg = "Error ! no codec has been found to handle this DICOM image";
logger.error(msg);
throw new IOException(msg);
}
}
else {
logger.error("Error ! Dicom stream is null, should not get this far!");
}
return imageBytes;
}
Any idea what I am missing ?
thx