Converting GDCM Image to Java BufferedImage

人走茶凉 提交于 2019-12-10 23:04:41

问题


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.

Thanks


回答1:


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


来源:https://stackoverflow.com/questions/5657817/converting-gdcm-image-to-java-bufferedimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!