Converting GDCM Image to 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 pop开发者_开发百科ulate bufferedImage?;
Can anyone tell me if I'm on the right track and how to complete this example.
Thanks
You can retrieve the raw buffer of pixel using:
byte[] str1 = new byte[ image.GetBufferLength()];
image.GetBuffer( str1 );
See full example at:
- http://gdcm.sourceforge.net/html/ScanDirectory_8java-example.html
or
- https://sourceforge.net/p/gdcm/gdcm/ci/master/tree/Examples/Java/ScanDirectory.java
or even
- https://github.com/malaterre/GDCM/blob/master/Examples/Java/ScanDirectory.java
精彩评论