本文介绍了将GDCM图像转换为Java BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用GDCM读取DICOM图像。有没有一种简单的方法可以使用GDCM读取dicom文件,然后将其转换为Java BufferedImage?到目前为止,我有以下
I am using GDCM to read in DICOM images. Is there an easy way to read in a dicom file with GDCM, and then convert it to a Java BufferedImage? So far I have the following
String filename = "C:\\test.dcm";
gdcm.ImageReader reader = new gdcm.ImageReader();
reader.SetFileName(filename);
reader.Read();
gdcm.Image image = reader.GetImage();
BufferedImage bufferedImage = new BufferedImage((int)image.GetRows(, (int)image.GetColumns(), BufferedImage.TYPE_USHORT_GRAY);
// How do I populate bufferedImage?;
有人可以告诉我我是否走对了,以及如何完成此示例。
Can anyone tell me if I'm on the right track and how to complete this example.
谢谢
推荐答案
您可以使用以下方法检索像素的原始缓冲区:
You can retrieve the raw buffer of pixel using:
byte[] str1 = new byte[ image.GetBufferLength()];
image.GetBuffer( str1 );
查看完整示例:
- http://gdcm.sourceforge.net/html/ScanDirectory_8java-example.html
或
- https://sourceforge.net/p/gdcm/gdcm/ci/master/tree/Examples/Java/ScanDirectory.java
甚至
- https://github.com/malaterre/GDCM/blob/master/Examples/Java/ScanDirectory.java
这篇关于将GDCM图像转换为Java BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!