Reading DICOM files
Introduction
DICOM files can be read from Java java.io.InputStream
objects, and java.io.File
objects. This is done through the org.dcm4che2.io.DicomInputStream
class, which extends java.io.FilterInputStream
. The DICOM file is typically read into a org.dcm4che2.data.DicomObject
implementation. For example:
DicomObject dcmObj; DicomInputStream din = null; try { din = new DicomInputStream(new File("image.dcm")); dcmObj = din.readDicomObject(); } catch (IOException e) { e.printStackTrace(); return; } finally { try { din.close(); } catch (IOException ignore) { } }
The DicomObject
may then be worked with.
When creating DicomInputStream
objects, the Transfer Syntax of the DICOM file will be extrapolated from the file contents. There may be cases where you need to read a raw dataset or when you already know the Transfer Syntax of the DICOM object. In these cases case you should use one of the constructors that specifies the Transfer Syntax as an argument. For example:
din = new DicomInputStream(new BufferedInputStream(new FileInputStream("image.dcm")), TransferSyntax.ImplicitVRLittleEndian);
This page has been viewed
Unknown macro: {tracking-info}
zero
times.