Bethan Palmer Bethan is a Java developer and a Java Champion. She has spoken at conferences including JavaOne/Code One, DevFest and NetBeans days. She has a degree in English Literature.

How to read DICOM Image files in Java

1 min read

In this post, I will be showing you how to read DICOM image files in Java using ImageJ or JDeli.

ImageIO and JAI do not have support for reading the Dicom file format. Due to this lack of support, we decided write our own Dicom Decoder which is available as part of JDeli.

First an introduction to Dicom images…

What is DICOM?

DICOM stands for Digital Imaging and Communications in Medicine. DICOM is a standard for medical images. It sets out how to store, exchange and transmit them. You can read more about DICOMs in our previous article explaining the file format.

How to read DICOMs using ImageJ

As ImageIO and JAI do not have support form DICOMs, you will need a third party alternative. For example, ImageJ (download and Javadoc) provides a DICOM decoder and viewer. The application provides a user interface which can be used to decode and view DICOM files. Alternatively, by adding the JAR file (included in the download) to your Java project you can use the DICOM class to decode and open DICOM files:

DICOM dcm = new DICOM();
dcm.open("image.dicom");
if (dcm.getWidth()==0)
        IJ.log("Error opening image.dicom");
else
        dcm.show();

How to read DICOMs using JDeli

JDeli is the image library we wrote to replace ImageIO and JAI (Javadoc and download). It has the ability to read DICOM files in Java:

//Read Image (can also be OutputStream or byte array)
File dicomFile = new File("dicomImage.dcm"); 
BufferedImage image = JDeli.read(dicomFile);

Or you can use the JDeli DicomDecoder directly:

DicomDecoder decoder = new DicomDecoder();
BufferedImage image = decoder.read(dicomByteData);

Why use JDeli?

JDeli offers a range of advantages over ImageIO and alternatives, including:

  • prevents heap related JVM crashes
  • implements unsupported image formats
  • reduce output file size
  • improve read/write performance
  • supports threading
  • superior image scaling algorithms

Learn more about JDeli, or download to try it yourself.

This article is part of our series on reading and writing image files in Java.

Bethan Palmer Bethan is a Java developer and a Java Champion. She has spoken at conferences including JavaOne/Code One, DevFest and NetBeans days. She has a degree in English Literature.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.