
Create Dicomdir From Dicom Files Example
Does DCMTK have a method to read a Dicomdir file instead of being forced to build dicomdir structure from the dicom files. I would assume reading dicomdir file directly( if present) could be speedier. Went thru the DicomDirInterface, but couldn't find any specific read dicomdir functionality. I read a message earlier from supposedly a.
By Jeff Mather, MathWorks
The DICOM (Digital Imaging and Communication in Medicine) format describes how to compose messages to send between imaging modalities (e.g., Computed Tomography (CT), Magnetic Resonance (MR), and ultrasound devices) and defines a set of operations for transmitting them across a network. These messages can also be written to files for offline storage on a picture archiving system, CD, or other type of storage device. DICOM-formatted messages combine images and metadata to create a rich description of a medical imaging procedure. This format is extremely detailed, with a specification that is more than 2,500 pages long.
MATLAB and the Image Processing Toolbox provide easy access to DICOM data. Accessing data in DICOM files becomes as easy as working with TIFF or JPEG images. This article presents examples of using DICOM and provides background information about the format.
DICOM has significantly improved communication between medical devices and lowered the cost and complexity of integrating hardware and software solutions. Before DICOM, each manufacturer used proprietary image formats and communications protocols to connect their hardware solutions with third-party products. Integrating medical hardware and software from different vendors meant translating from one vendor's protocols to another's. This process was chaotic and fraught with difficulty. A cottage industry developed to provide data translation services.
With the advent of DICOM as a formal standard in 1993, one protocol replaced many protocols and formats. DICOM is the common format, easing integration of solutions from different vendors. For example, it is possible to integrate a MR scanner from GE Medical Systems with a picture archive system (PACS) from Agfa and another vendor's film printer without using translation devices. Integration isn't limited to just hardware. Software such as MATLAB that supports DICOM can share images with all of these devices, provided that each of the hardware devices has implemented the necessary DICOM services.
In medical imaging, a patient is subject to an imaging study, which may contain multiple series of images. Each series is performed on a single modality such as an MR, CT, or X-ray device and can have multiple related images. Suppose that we have a study consisting of a series of 20 transverse MRI brain images and we want to read them into MATLAB. (These 20 images are stored in 20 DICOM files with names such as brain_017.dcm, which you can download from MATLAB Central if you want to run the examples.) Let's suppose we know that each image is 256-by-256 and contains signed 16-bit data. We can read the series with the following code:
After running this code, the MATLAB workspace contains a 4-D array with the image data, and a plot of the MR slices appears.
You can use MATLAB and the Image Processing Toolbox to perform multiple tasks with this data. For example, MATLAB provides sophisticated volume visualization techniques to reconstruct a 3-D surface from these slices and then apply surface and lighting effects. The example in the Help section for the isocaps
function shows this implemented. The imtransform
and tformarray
functions in the Image Processing Toolbox make it easy to extract slices in different orientations from the transverse data. For example, the 'Extracting Slices from a 3-Dimensional MRI Data Set' example shows how to extract saggital slices from a similar dataset. You can also use the morphology functions within the Image Processing Toolbox to perform operations such as image segmentation, feature extraction, and image statistics. Alternatively, you can write your own functions to perform volume estimation, shrinkwrapping, etc.
In the previous example, we made several assumptions as we preallocated the storage array. All of these assumptions were based on metadata that exists in the DICOM file. Furthermore, the values of the image pixels are limited to a narrow band in the total possible dynamic range of the image, so we had to pass an empty array as a special argument to montage
to rescale the data. Let's use the metadata attributes in the DICOM files to (1) intelligently preallocate our array and (2) rescale the data values to fill the 16-bit dynamic range.
Because all images in a series must have the same dimensions and bit-depth, we only need to get the metadata from one image in the series to preallocate the array. The Image Processing Toolbox function dicominfo
returns the metadata from a DICOM file.
As you can see, there are many metadata values, or attributes. The values for 'Rows,' 'Columns,' and 'BitsStored' tell us exactly what we need to know, and we can rewrite the code that reads the image stack.
We still have to take for granted that the image contains signed data&msdash;a 'PixelRepresentation' value of '1' indicates that type of, where b is the minimum x value and m is a constant ratio derived from the input and output ranges.
As shown in the previous example, a typical DICOM file contains numerous attributes. The reason for this is that DICOM messages encapsulate all of the information about a medical imaging procedure, including details about the patient, study, imaging modality, and image series in addition to the image frame stored in the file. Together, all of these attributes comprise an Information Object.
The DICOM specification contains numerous Information Object Definitions (IODs), such as MR Image, Ultrasound Multiframe Image, and Radiotherapy Plan. The DICOM files in the examples above contain MR Image Information Objects. dicomread
understands most IODs that are listed in the DICOM specification.
Free website builder software. For more information, visit the.For additional language downloads for Expression Web, please select one of the following:. .Expression Web 4 gives you the tools you need to produce high-quality, standards-based Web sites: built-in support for today’s Web standards, sophisticated CSS design capabilities, and visual diagnostic tools. Whether you work with PHP, HTML/XHTML, CSS, JavaScript, ASP.NET or ASP.NET AJAX, Expression Web makes it faster and easier to create and maintain exceptional web sites.Please note: This free version of Expression Web is not eligible for Microsoft technical support and is community support.
IODs are defined in terms of smaller functional units, or modules, which correspond to specific real-world objects, such as patients, imaging equipment, etc. The hundred-or-so modules in DICOM describe everything that could be combined to make a DICOM information object. For example, the following table lists the modules that constitute an MR Image IOD:
ModuleDescription Patient Details about the patient General Study General information about the study, a set of imaging procedures Patient Study (U) Information about the patient at the time of the study General Series General information about one particular imaging procedure Frame of Reference Information to spatially relate images in a series General Equipment General information about the image modality that produced the series General Image Details that identify and describe an image within the series Image Plane Slice thickness/location/spacing and other orientation details Image Pixel The actual image pixels and information on how to interpret them Contrast/Bolus (C) Details about medication given at the time of imaging MR Image Values specific to magnetic resonance imaging Overlay Plane (U) Graphics or bitmapped text to display with a particular image VOI LUT (U) Information to transform the contrast or intensity of the image SOP Common Date/time of message creation and other generic DICOM details
Some modules, such as Patient, General Study, General Equipment, and Image Pixel, are found in many IODs. Other modules appear only in specific IODs. The MR Image module, for example, is only part of the MR Image IOD.
The IOD contains modules that describe the patient, study, series, and images for a particular medical imaging procedure. Also, notice that some modules have a '(C)' or '(U)' near their name, which means that for this IOD they are 'conditionally required' or 'user optional' modules; the conditional and user optional modules may or may not appear in every MR Image IOD. For example, the Contrast/Bolus module will only appear if medication is given at the time of imaging, and the VOI LUT module does not have to be implemented by the device that writes the DICOM file.
All of the modules and attributes are defined in PS 3.3 of the DICOM specification, which are available online from the National Electrical Manufacturer's Association. Additionally, all of the defined attributes are listed in a data dictionary. Vendors sometimes define private attributes that are specific to their hardware. While you do not need to do anything special to read private attributes with dicomread
or dicominfo
, if you want to provide additional information about attributes that are not part of the DICOM specification, you can provide your own data dictionary.
We will now create a new DICOM file. Writing a new file requires an image and metadata. We created a new image with the scaled data in one of the examples above, and dicomwrite
and dicominfo
will help us create the metadata we need.
To write a DICOM file, simply use dicomwrite
in the Image Processing Toolbox. Currently, this function supports creating Secondary Capture (SC) Image IODs, which contain all of the pixel data and metadata necessary for correctly interpreting the image. Essentially, an SC image is similar to what you would generate with a framegrabber, or if you had generated the image yourself from scratch or from another image (as in the example above). Metadata about the patient, image, and study will be present, but information about the original hardware that produced the image will not.
To write the tenth frame of the scaled image using default metadata to a new file, use dicomwrite
with its basic syntax:
In this example, dicomwrite
infers the metadata that is required, filling in blank values where appropriate. To override default values, provide dicomwrite
with a structure containing attributes:
dicomwrite
picks the values that apply to the Secondary Capture IOD and ignores the rest. When dicomwrite
makes a new file, it is actually performing two operations. First, it creates a Secondary Capture information object. Then it encodes the information object's attributes, turning them into a stream of bytes that are written to the output file. This last step demonstrates the DICOM concept of services.
A service provides a set of concrete actions to perform on objects. Common services include Storage, Print Management, Verification, and Query/Retrieve. When dealing with network messages, services are implemented by adding extra attributes to the message and then sending a series of instructions to the receiving machine or application, which deciphers the extra attributes to figure out what to do with the message. When working with DICOM files, the attributes are added to the file, and writing or reading the file replaces the transfer of instructions.
Writing a file containing DICOM data is very much like performing the Storage service. Essentially, the IOD's attributes plus those for the Storage service are combined and 'frozen' when written to disk. Reading the file 'thaws' the IOD and service attributes, and the entire context of what to do with the information is preserved.
Encoding rules found in the DICOM standard provide the algorithm for transforming attributes into a series of bytes to be transmitted or stored. Different byte-ordering schemes can be used during encoding, and image pixels can be compressed using numerous techniques, such as JPEG or run-length encoding. In the calls to dicomwrite
above, the files are encoded using so-called 'implicit VR, little endian' style, and the pixels are not compressed.
A host of Transfer Syntaxes unambiguously define how to decode a DICOM message. One of these transfer syntaxes appears at the beginning of a DICOM network transmission or at the start of a DICOM file. If both the sender/writer and receiver/reader support the same transfer syntax, communication proceeds. Otherwise, communication fails. The DICOM features in MATLAB and the Image Processing Toolbox support the most commonly used transfer syntaxes.
With all of these possibilities-IODs, optional modules, services, and transfer syntaxes-it can be difficult to know exactly how well two modalities will interact. Implementing a service requires knowing which attributes to send or receive. Furthermore, making the service useful frequently requires knowing what kind of data to put into attributes and verifying that the information is correct. Consequently, few manufacturers support the full set of 'Service-Object Pairs' that are possible in DICOM. In addition, different applications support different transfer syntaxes.
Fortunately, every application that implements part of DICOM should know what it supports. Manufacturers publish the information about the services, IODs, and transfer syntaxes that they support in DICOM conformance statements. By comparing statements from two different vendors, you can identify whether the two applications can share information.
DICOM makes it easy to acquire and put medical images into a file. It is becoming more prevalent in the medical field.
Many medical device manufacturers and software manufacturers are adding DICOM to just about any product that can work with medical images and data.
Using MATLAB with the Image Processing Toolbox provides easy access to medical images, modality metadata, and patient information within DICOM files. They also provide numerical and image processing algorithms, GUI-building tools, and visualization techniques. With MATLAB, the Image Processing Toolbox, and DICOM it is possible to quickly view medical images, design and test new modalities, and create GUI-driven medical image analysis systems.
Published 2002
Products Used
Learn More
View Articles for Related Industries
This is a continuation of my previous tutorial in which we looked at what a DICOMDIR file is, and also reviewed the role these special files play in the overall media management aspects related to DICOM processing. In that article, we also explored how to read and display information contained in these special files using a .NET library called 'fo-dicom .NET toolkit'. Download fable 2 pc ripped. In this short tutorial, we will look at how to create DICOM directories and also cover some additional theory to solidify our understanding of this area.
This is part of my series of articles on the DICOM standard. If you are totally new to DICOM, please have a quick look at my earlier article titled “Introduction to the DICOM Standard” for a quick introduction to the standard. You may also want to look at my other tutorial titled “DICOM Basics using .NET and C# - Making Sense of the DICOM File” to understand the structure of a DICOM file. This tutorial also assumes that you know the basics of C# or any equivalent object-oriented language such as Java or C++.
Some Theory
If you recall my earlier tutorial on DICOM association/negotiations, I mentioned that DICOM applications take on different roles when performing any DICOM-related operations. In addition to both composite and normalized DICOM operations which deal with aspects such as sending, receiving and printing of DICOM images, there is another category of operations called 'storage media operations' which deal with reading or encoding content from and to storage media. These operations at their core handle data essentially as serialized files. Unlike the commands involved during composite and normalized operations, association negotiation to negotiate transfer syntaxes, etc is not feasible, and the roles played by the various actors are therefore predefined. Just like roles such as 'Service Class User (SCU)' and 'Service Class Provider (SCP)' which the actors play during composite and normalized DICOM operations, applications play various roles during media storage operations as well. The primary roles involved during storage media-related operations are File Set Creator (FSC), File Set Reader (FSR) and File Set Updater (FSU). For instance, any application that reads a DICOMDIR file plays the role of a 'File Set Reader'. And when creating a DICOMDIR file, the application plays the role of a 'File Set Creator', and when updating a DICOMDIR file plays the role of a 'File Set Updater'. Please also note that the DICOM standard stipulates that only modification of the DICOMDIR file is permitted. No modification is permitted to the actual contents of the files or images that are referenced by the DICOMDIR file.
It is interesting to note that the DICOMDIR file itself is a valid DICOM file (uses the 'Basic Directory IOD' structure) and information is encoded into it using the 'Explicit VR Little Endian Transfer Syntax (UID=1.2.840.10008.1.2.1)' as no negotiation is permitted as mentioned earlier. The Basic Directory IOD structure on which DICOMDIR file is based on is organized as essentially a hierarchy of 'directory records' starting with a 'root directory record' which is then linked to one or more child 'directory records' and these themselves may in turn have a reference to other lower level directory records. Besides the root record which carries information about the overall file (meta-information), there are essentially four types of information each of the directory records can manage ('patient', 'study', 'series' and 'image') although not all these directory record types need to be present. Depending on the type of directory record, relevant information is encoded into it in order to allow the processing application to retrieve it for any processing. For example, a directory record dealing with the image file may carry information such as the location of the file relative to the DICOMDIR file as well as transfer syntax of the file and its abstract syntax information such as the SOP class and instance UID, etc. There is lot more to this area than I have mentioned here but I hope this should be enough to give you an idea of what happens 'under the covers' so to speak. Please refer to the DICOM Standard for more information on this area. Enough theory. Let us proceed to look at how to create DICOM directories using the fo-dicom toolkit.
“Your heart is the size of an ocean. Go find yourself in its hidden depths.” ~ Rumi
Before We Get Started…
Much like my previous programming examples, I will use the most bare minimum code and approach to help illustrate the concepts that I cover in this tutorial. This means that the code I write here is best suited to simply show the concept that I am trying to explain and is not necessarily the most efficient code to deploy in real life and in your production application.
To get started, you will need to configure a few things on your machine including a .NET development environment as well as the Fellow Oak (fo-dicom) DICOM library before you can run the example if you want to try this out yourself.
Download a .NET IDE or Editor such as Visual Studio IDE or Visual Studio Code (even a text editor should suffice)
Download the Fellow Oak DICOM library either through NuGet Package Manager or download the source code directly from here
You can also find the source code used in this tutorial on GitHub
I have included some sample DICOM images along with the source code to follow along. However, please feel free to use your own images as required
Creating DICOMDIR Files using Fellow Oak (fo-dicom) Toolkit
Like I mentioned in my previous tutorial on reading DICOMDIR files, the fo-dicom library provides a number of classes to perform read and write operations on DICOM directory files. These classes can be found in the Dicom.Media namespace of the library. We will once again use our familiar friend, the DicomDirectory class, to create a DICOM directory file. Here, I am essentially creating an instance of this class and adding any DICOM files that are found underneath a specified location. Since the DICOM Directory is itself a DICOM file, we can utilize the many convenience extension methods that the fo-dicom library provides on the DicomMFile class to operate on it. Some of these methods that can be very useful especially for the purposes for display of information include WriteToString, WriteToConsole, WriteToLog and WriteToXml. Here, I am showing the output from the WriteToString method to display the entire contents of the DICOMDIR file.
“May you always have open breezy spaces in your mind.” ~ Sanober Khan
The partial output of running the program above is seen below. Hopefully, this reinforces the hierarchical organization of information which I alluded to earlier (using 'directory record types' and linking of these records to each other). As you can see, our newly created DICOMDIR file has a root directory record showing high level information about the DICOMDIR file itself, and the root directory record is linked to additional information which are also encoded as directory records organized by patient, then by study, then by series and then by images. Please refer to my previous tutorial on reading DICOMDIR files if you want to extract this meta data for additional processing that may be necessary to address any requirements.
That concludes this short tutorial on creating DICOM directory files. Hopefully, I have covered enough theory for you to dig deeper into this area yourself. Please also refer to my my previous tutorial on reading DICOMDIR files for some additional testing tools that can be very useful during any software testing efforts. If you have any questions or comments regarding this tutorial, please feel free to send me an email. Please note that I may not get back to you right away due to work and other commitments. In my next tutorial in this series, we will move on to another interesting area of the standard namely DICOM Communications/Networking. I will start by showing how to check for DICOM connectivity using C-Echo or “DICOM ping” as it is sometimes called. See you then.