Problem generating a BufferedImage directly from DICOM file containing JPEG Lossless image
See original GitHub issueI am trying to create a BufferedImage from a DICOM (DCM) file containing JPEG Lossless data (transfer syntax: 1.2.840.10008.1.2.4.57). I believe #182 added support for this.
After including the Twelve Monkeys JPEG Plugin, I expected the following to work.
BufferedImage img = ImageIO.read(dcmFile);
However, I still received a codec error and soon realized that the Twelve Monkeys JPEG Reader was not being loaded.
I then tried to force my application to use the Twelve Monkeys JPEG Reader like this:
ImageInputStream iis = ImageIO.createImageInputStream(dcmFile);
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
if (readers.hasNext()) {
ImageReader reader = readers.next();
reader.setInput(iis, true);
BufferedImage img = reader.read(0);
}
However, that triggered the following exception.
ImageIO ImageReader for JPEG failed
javax.imageio.IIOException: No SOF segment in stream
at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.getSOF(JPEGImageReader.java:762)
at com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:334)
at javax.imageio.ImageReader.read(ImageReader.java:939
I feel like there is something simple that I might be missing, and I would appreciate any guidance. Do I need to somehow extract the JPEG data from DICOM file prior to attempting the conversion to a BufferedImage? The test data posted by @HermannKroll in #234 is just the JPEG data that was somehow extracted from a DICOM file. Is extracting the JPEG data in that manner necessary? If so, would anyone be able to point me in the right direction on how to go about doing that?
Thanks for any help!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top GitHub Comments
@alancoler There is a LUT in your dicom image. For every pixel value, the result pixel is found by a lookup in the LUT. I would check to make sure the data is decompressed by the decompressor before being processed by the LUT. dcm4che is complaining that pixel value 0x92700 is not found in the LUT.
@alancoler I’m sorry I can’t help you much here… I haven’t tested @msfanous solution above, but it seems to have worked for him. But as far as I understand, it’s used just in a few very specific cases (ie. to handle JPEG Lossless). I’m not sure it applies to your file.
Anyway, if for some reason DCM4CHE can’t be configured to delegate to the TwelveMonkeys JPEGImageReader, there’s nothing we can do about that (no TwelveMonkeys code is involved, according to your stack trace). You might get some better answers if you ask the people at https://dcm4che.org/, so I suggest starting there. 😃
Best regards,
– Harald K