Reputation: 174
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?
Upvotes: 0
Views: 1637
Reputation: 6306
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
Upvotes: 1