DICOM
Files ending in .ima or .dcm are in the DICOM medical image format. It is a widely used format that enjoyed great popularity but, in the diffusion MRI community at least, has been mostly superseded by NIfTI.
You can confirm that you're dealing with DICOM data by running the following two commands:
strings <SUSPECTED_DICOM_FILE> | grep -i "dicom" strings <SUSPECTED_DICOM_FILE> | grep -i "dcim"
If you get output, that means that the DICOM magic string shows up somewhere in the file. Another good indication that you're dealing with some sort of DICOM data is that your collaborator told you so.
Volumes as DICOMs
A single DICOM file stores only one 2-D image, and so various strategies exist for storing and transferring volumes and collections of volumes as DICOM images. Most commonly, you'll just get a directory full of dozens (if not hundreds or thousands) of .ima or .dcm files, each one storing a single slice. Some other strategies crop up from time to time, though, to represent a whole volume or a collection of volumes as a single file. If you have reason to believe that your data should be in DICOM format but they seem a little funky, they might be stored as a tarball or in "mosaic" format. Here are a couple clues that indicate you should consider these possibilities:
- Matlab or Medcon claims that your file is not a DICOM
- the file size is much larger than you'd expect for a single slice (which should be on the order of 100kB)
- the number of files is much lower than you'd expect for a collection of slices (hundreds or maybe even thousands)
- the DICOM header reports an unusually large slice resolution (> 256x256)
Tar
Sometimes many DICOM files (or even a whole directory structure of different files) are concatenated together into a single file using the Unix tar utility. If your presumed DICOM file seems a little funky, it might actually be a "tarball" (as the result of a tar concatenation is called) of DICOMs. Here's how to check:
tar -tf <SUSPECTED_DICOM_FILE>
If you get non-error output, especially a list of *.dcm or *.ima filenames, then you're dealing with a tarball of DICOMs. Extract the original images as follows:
tar -xf <SUSPECTED_DICOM_FILE>
The tarball may also have been compressed after concatenation; in which case you would need the -z option in the above commands:
tar -tzf <SUSPECTED_DICOM_FILE> tar -xzf <SUSPECTED_DICOM_FILE>
Mosaic
An unusual storage strategy for DICOM-formatted medical images is the so-called "mosaic" scheme, in which a three-dimensional voxel volume is represented as a two-dimensional flat image. The volume is divided up into X-Y slices which are then arranged in 2D like a tile floor, with Z increasing left to right, top to bottom. You can spot one of these by visual inspection or if the header shows an image size much larger than a single slice---a single slice is usually 128x128 or 256x256 voxels, while a mosaic file may be much larger than that, depending on the Z resolution of the volume. There are Matlab scripts available that automatically split the slices in a Mosaic image, assemble them into a single volume, and write them out in the desired format.
Handling DICOMs
Matlab
Matlab has extensive built-in support for DICOM header and image data I/O with the dicominfo, dicomread, and dicomwrite functions. This is nice for quickly creating DICOM processing scripts to be run manually, but Matlab is relatively slow and difficult to call from non-interactive scripts. Therefore it's encouraged to port Matlab code into another language (preferably C++ or Python) for inclusion in the diffusion processing pipeline.
Despite the shortcomings of including Matlab scripts in the pipeline, flexibility and ease of development have led to its use for handling the diverse storage strategies associated with DICOM data. Check out the list of diffusion MRI Matlab scripts for useful code that's already been written.
Python
- pydicom --- a pure Python DICOM library
- pydicomlib --- a Python wrapper around dicomlib, below
C/C++
- GDCM --- "Grassroots DICOM" library
- DCMTK --- the DICOM toolkit library
- dicomlib --- Yet another DICOM library, written at Sunnybrook Health Sciences Centre, Toronto
Java
Tools
- medcon --- Command-line tool for converting among tons of different medical image formats
- DICOM3tools --- Command-line tool for reading DICOM headers, written by a member of the DICOM standards committee