2

I'm trying to convert a DICOM image in jpeg2000 using imageio as in the below code, the same procedure is explained in oracle documentation, but doesn't work! I don't understand what I'm doing wrong. The Java Advanced Image I/O library is installed into the JRE.

Using: ImageIO.getReaderFormatNames() and ImageIO.getWriterFormatNames() it can be verified that DICOM and JPEG2000 are supported!

There are no errors thrown, but it takes too long to write the file, and the output file is corrupted.
Thank you in advance...

 public void convert2JPEG(File sourceFileName) throws IOException{

    Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
    ImageReader reader = iter.next();

    if(reader == null) {
        log.error("Could not locate any Readers for the DICOM format image.");
        return;
    }

    File sourceFile = new File (sourceFileName);
    ImageInputStream iis = ImageIO.createImageInputStream(sourceFile);
    BufferedImage bi;
    try{
    bi = ImageIO.read(iis);
        File outputFile = new File("outputFileName");
    String format = "jpeg 2000";
    ImageIO.write(bi, format, outputFile);
    } catch(Exception e){
        log.info("ERROR: " + e);
    }finally {
        iis.close();
    }
}
lindi
  • 3
  • 1
lindi
  • 21
  • 1
  • 3
  • Right out-of-the-box, the supported image formats in Java SE 7 appears to be JPEG, PNG, GIF and (W)BMP (as obtained when calling `ImageIO.getReader/WriterFormatNames()`). Could you please explain how you have come to the conclusion that _DICOM_ and _JPEG2000_ are supported? – Anders Gustafsson Sep 23 '12 at 17:34
  • 1
    @AndersGustafsson: I imagine the questioner has installed the Java Advanced Image I/O library. That adds the ability to read and write TIFF and JPEG2000, but I'm not sure about DICOM. – Luke Woodward Sep 23 '12 at 17:44
  • @LukeWoodward Thanks for the clarification. Generally I would recommend usage of a DICOM toolkit to facilitate this type of conversions. I think that David Clunie's open source [Pixelmed](http://www.pixelmed.com/index.html#PixelMedJavaDICOMToolkit) Java DICOM Toolkit is able to write images in JPEG2000 format. – Anders Gustafsson Sep 23 '12 at 19:08
  • @AndersGustafsson thank you for answering. It seam that pixelmed doesn't support the writing of jpeg2000! Do you have any other idea? – lindi Jan 08 '13 at 20:59

1 Answers1

1

JAI Image IO does not support DICOM to my knowledge, but does support JPEG2000. Do note that there is no Windows 64-bit version of JAI (that may be an issue for you too). I am surprised it is not giving any kind of error.

However, I agree with Anders that the best course for converting DICOM would be to use a toolkit. I'd suggest DCM4CHE2 (http://www.dcm4che.org/confluence/display/d2/dcm4che2+DICOM+Toolkit). They have a number of command line tools for doing exactly what you are suggesting, and Dicom[Input/Output]Stream classes for reading and writing DICOM.

cneller
  • 1,542
  • 1
  • 15
  • 24