Direct encapsulationDICOM permits binary non-image documents like PDF and MPEG-2 or MPEG-4 video to be encapsulated in DICOM objects. Although the creation or decoding of such documents is out of the scope of DeCaMino, you can encapsulate or extract them.
Here is an example of creating and writing of a DICOM object including a video that is read from a file. The video must be encoded in an MPEG-TS or MPEG-4 container:
DicomWriter writer = new DicomWriter(); File out = new File("video.dcm"); writer.setOutput(out); FileImageInputStream fiis = new FileImageInputStream("video.mp4"); DicomMetadata dmd = new DicomMetadata(); /* Set some data elements in dmd such as date, patient, etc... */ dmd.setPixelData(fiis, null, true); writer.write(dmd);DeCaMino will probe the MPEG-4 file
video.mp4and read the necessary information (size and length of the video) in order to fill out the required DICOM data elements to obtain a conform object. The transfer syntax can also be determined automatically from the video file.
More generally, pixel data can be set from a binary stream even in the non-video case. For example a JPEG-2000 codestream file can be directly encaspulated without requiring its decoding, thus saving computing resources.
Extracting the raw pixel data from an existing DICOM file is also possible:
DicomReader reader = new DicomReader(); reader.setInput(new File("image.dcm")); DicomMetadata dmd = reader.getDicomMetadata(); ImageInputStream iis = dmd.getPixelData(0);The resulting input stream can then be read and, for instance, dumped to a file.
PDF can be encapsulated in or extracted from a DICOM object with a similar mechanism, using input or output stream.