我正在寻找一种用Java读取压缩DICOM文件的方法。使用Jpeg2000压缩DICOM。 Java高级映像IO在MAC OS中没有库,因此我在使用DCM4CHE时遇到问题。 ImageJ也不支持压缩的DICOM文件。
File myDicomFile = new File("IM-0001-0001.dcm");
try {
DicomInputStream dis = new DicomInputStream(myDicomFile);
Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
ImageReader reader = (ImageReader) iter.next();
DicomImageReadParam param = (DicomImageReadParam) reader.getDefaultReadParam();
ImageInputStream iis = ImageIO.createImageInputStream(myDicomFile);
reader.setInput(iis, false);
BufferedImage bi = reader.read(0, param);
File myJpegFile = new File("IM-0001-0001.jpg");
OutputStream output = new BufferedOutputStream(new FileOutputStream(myJpegFile));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
encoder.encode(bi);
output.close();
} catch (Exception e) {
System.out.println(e.getStackTrace());
}
上面的代码适用于未压缩的DICOM,但是使用压缩的DICOM会产生以下错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.medialib.codec.jp2k.Decoder.decode_init(Ljavax/imageio/stream/ImageInputStream;J)J
at com.sun.medialib.codec.jp2k.Decoder.decode_init(Native Method)
at com.sun.medialib.codec.jp2k.Decoder.<init>(Decoder.java:53)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.<init>(J2KRenderedImageCodecLib.java:158)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib.read(J2KImageReaderCodecLib.java:367)
at org.dcm4che3.imageio.plugins.dcm.DicomImageReader.read(DicomImageReader.java:284)
at Main.main(Main.java:31)
任何建议都将受到赞赏。