Get/Set attributes from an object
Attributes (patient name, exam date, acquisition parameters, etc.) in DICOM objects are encoded as data elements. Manipulation of data elements is performed using class DataSet
. When a DICOM object is read by the plugin, its associated stream metadata, an instance of DicomMetadata
, can be used to get or set various information about the object, one being the full data set.
DicomReader reader = new DicomReader(); reader.setInput(new BufferedFileImageInputStream(new File("image.dcm"))); DicomMetadata dmd = reader.getDicomMetadata(); DataSet ds = dmd.getDataSet(); String patient_id = ds.getString(Tag.PatientID); LocalDate date = ds.getLocalDate(Tag.StudyDate); BufferedImage image = reader.read(0); ds.set(Tag.PatientName, "Anonymized");
DicomReader
is a subclass of the standard ImageReader
. Instances can be created directly like in the example, or using the ImageIO service provider mechanism and asking for an image reader providing the "dicom"
format. getDicomMetadata()
is just a shortcut for (DicomMetaData) getStreamMetadata()
.
Tag
is a dictionary class containing the numeric tags of all DICOM attributes, using the standard keywords introduced in DICOM 2009.
The value of a data element is set and get using a Java class reflecting the data element type (its DICOM Value Representation), but this restriction is loose: any element value can be read as string using getString
, person names can be set with strings or with instances of specific class PersonName
which can handle multi-component names, numbers are automatically converted if necessary, and so on.