2012-09-23 32 views
2

我想在下面的代碼中使用imageio在jpeg2000中轉換DICOM圖像,同樣的過程在oracle文檔中有解釋,但不起作用!我不明白我做錯了什麼。 Java高級映像I/O庫安裝在JRE中。使用imageio編寫jpeg2000的問題

使用:ImageIO.getReaderFormatNames()ImageIO.getWriterFormatNames()可以驗證是否支持DICOM和JPEG2000!

沒有錯誤拋出,但寫入文件需要很長時間,並且輸出文件已損壞。
預先感謝您...

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(); 
    } 
} 
+0

即時可用的Java SE 7中支持的圖像格式似乎是JPEG,PNG,GIF和(W)BMP(調用'ImageIO.getReader/WriterFormatNames()'時獲得)。你能否解釋一下你是如何得出結論是_DICOM_和_JPEG2000_被支持的? –

+1

@AndersGustafsson:我想提問者已經安裝了Java高級圖像I/O庫。這增加了讀寫TIFF和JPEG2000的能力,但我不確定DICOM。 –

+0

@LukeWoodward感謝您的澄清。通常我會推薦使用DICOM工具包來促進這種類型的轉換。我認爲David Clunie的開源[Pixelmed](http://www.pixelmed.com/index.html#PixelMedJavaDICOMToolkit)Java DICOM Toolkit能夠以JPEG2000格式編寫圖像。 –

回答

1

JAI圖像Io不支持DICOM據我所知,但不支持JPEG2000。請注意,沒有Windows 64位版本的JAI(這也可能是您的問題)。我很驚訝它沒有給出任何形式的錯誤。

但是,我同意安德斯轉換DICOM的最佳方法是使用工具包。我建議DCM4CHE2(http://www.dcm4che.org/confluence/display/d2/dcm4che2+DICOM+Toolkit)。他們有許多命令行工具用於完成您所建議的內容,以及用於讀取和寫入DICOM的Dicom [輸入/輸出]流類。