0

I am stuck in 1.2.840.10008.1.2.4.70 - JPEG Lossless, Non-Hierarchical, First-Order Prediction while converting DCM to jpg using ImageIo.

I have installed JAI ImageIO as instructed here, and ImageIO.getReaderFormatNames() is giving raw jpeg tif JFIF WBMP jpeg-lossless jpeg-ls PNM JPG DICOM wbmp PNG JPEG dicom jpeg 2000 tiff BMP JPEG2000 RAW JPEG-LOSSLESS jpeg2000 GIF TIF TIFF jpg bmp pnm jfif png JPEG 2000 gif JPEG-LS.

However, I am getting Exception in thread "main": java.lang.IndexOutOfBoundsException: imageIndex out of bounds, while reading buffered image using reader. This is my reader code:

    ByteArrayInputStream bais = new ByteArrayInputStream(dicomData); //byte array of DICOM data
    ImageIO.scanForPlugins();
    Iterator<ImageReader> iter = ImageIO
                    .getImageReadersByFormatName("jpeg-lossless");
    ImageReader reader = (ImageReader) iter.next();
    ImageReadParam param = (ImageReadParam) reader.getDefaultReadParam();
    ImageInputStream iis = ImageIO.createImageInputStream(bais);
    reader.setInput(iis, false);        
    BufferedImage  buff = reader.read(0, param); // Error at this line 'imageIndex out of bounds!'
    iis.close(); 

Is this right way to do this or any other way?

Harald K
  • 26,314
  • 7
  • 65
  • 111
Dharmraj
  • 164
  • 1
  • 15
  • Can't see much wrong with your code. You could try re-arranging your code, and then call `iter = ImageIO.getImageReaders(iis)` instead of `getImageReadersByFormatName(...)` (which is the more common way to get a reader). Most likely, the JPEG-LOSSLESS capable `ImageReader` cannot read your data though. The `IOOBException` indicates that the reader doesn't find any images in the data at all (verify by testing `reader.getNumImages(true)`). You might have to "massage" `dicomData` a little, to have the reader accept it. – Harald K Sep 29 '14 at 08:16
  • Hi HaraldK, Thanks for replying,I rearranged my code and use ImageIO.getImageReaders(iis) as you suggested but now its giving error javax.imageio.IIOException: Unsupported JPEG process: SOF type 0xc3. And reader.getNumImages(true) giving 1. – Dharmraj Sep 29 '14 at 10:45
  • 1
    Hmmm.. Seems you got the wrong `ImageReader` after the code change. Verify to see if `reader` really is an instance of the `CLibJPEGImageReader` or just the normal `JPEGImageReader`. – Harald K Sep 29 '14 at 11:08
  • Is there any way to verify that and get right image reader? when i print image reader that getting is : org.dcm4che2.imageioimpl.plugins.dcm.DicomImageReader@1935e6f – Dharmraj Sep 29 '14 at 12:47
  • Ok... I don't know this reader, looks like some 3rd party reader you have installed. I was expecting the `CLibJPEGImageReader` (from jai_imageio.jar) as you tagged your question with JAI... The JAI reader should be able to read SOF type 0xc3 (Lossless sequential, Huffman encoded) I think. – Harald K Sep 29 '14 at 12:54
  • Yes, Actually i am converting .dcm to jpeg. The dicomData is byte array of .dcm file and i am getting as buffered Image to write as jpeg. This usage ImageIO to do. – Dharmraj Sep 29 '14 at 13:07
  • Thanks haraldk, it was help full hint for image reader. – Dharmraj Oct 09 '14 at 13:22

1 Answers1

1

You cannot use a jpeg-lossless ImageReader to read a dicom part 10 file. You should consider using dcm4che imageio ImageReader to read the file. When it actually gets to the pixel data portion of the content, it will utilize the JAI jpeg image reader to decompress the image content.

http://www.dcm4che.org/confluence/display/d2/dcm4che2+DICOM+Toolkit

Brett Okken
  • 6,210
  • 1
  • 19
  • 25