Direct write
In the previous example, we received a DICOM object from the network. Imagine you'd like to write it back to the file system after just checking some data elements. If you use the normal Image I/O procedure to write the object, you'll decode the image into a BufferedImage
, then re-encode it with the write
method of the DICOM writer. This is fine if you need to change the encoding process (the DICOM transfer syntax), but is a waste of time and memory if you do not. Moreover, the decoding-recoding procedure could produce some small discrepancy between the input and output images due to rounding errors.
To address this issue, DicomWriter
provides a write(DicomMetadata dmd)
method that will perform a direct write of the DICOM object without touching the encoding of pixel data. This method could also be used to write DICOM objects that does not contain images, such as worklist, reports, etc.
Here is the Storage SCP example updated to write the received object to a file named after the object SOP instance number:
DicomReader reader = new DicomReader(); DicomWriter writer = new DicomWriter(); StorageSCP scp = new StorageSCP(); reader.setInput(scp); DicomMetadata dmd = reader.getDicomMetadata(); File out = new File(dmd.getSOPInstance()); writer.setOutput(out); writer.write(dmd);