DICOM

From VrlWiki
Jump to navigation Jump to search

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) 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 it seems a little funky, it 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.

Code

The following scripts to handle DICOM mosaic files can be found in /map/gfx0/common0/diffusion/Interface/bin/data/:

  • processMosaics.m --- split all mosaic files matching a given pattern into DICOM and MRIimage files
  • splitMosaic.m --- split a single mosaic file into a Matlab data array
  • writeMosaicSlices.m --- write a collection of Matlab data volumes to DICOM and MRIimage files

All of these can be launched non-interactively with matlabLauncher.py.

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.

Useful Links