question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem generating a BufferedImage directly from DICOM file containing JPEG Lossless image

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rich-coecommented, Aug 5, 2019

@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.

1reaction
haraldkcommented, Aug 5, 2019

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error while converting .dcm to jpeg of type jpeg-lossless
When it actually gets to the pixel data portion of the content, it will utilize the JAI jpeg image reader to decompress the...
Read more >
dicom to jpeg conversion produces overexposed image
I'm trying to convert a dicom file to jpeg using a dcm4che in Java but having an issue with one particular file (see...
Read more >
Unable to Compress DICOM Image File wtih Lossless JPEG
Recently, I have been having trouble with compressing a DICOM image file with lossless JPEG. I have been following the code example at ......
Read more >
Managing DICOM images: Tips and tricks for the radiologist
A simple and easy method of ensuring this is by converting and exporting the DICOM file into other image formats such as JPEG...
Read more >
Converting JPEG to DICOM using dcm4che 2 - samucs-dev
So if our image has samples per pixel equals to 3, it has colors (YBR_FULL_422), else it's a grayscale image (MONOCHROME2). The following...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found