DICOM: Difference between revisions

From VrlWiki
Jump to navigation Jump to search
Jadrian Miles (talk | contribs)
No edit summary
Jadrian Miles (talk | contribs)
No edit summary
Line 1: Line 1:
Files ending in <tt>'''.ima'''</tt> or <tt>'''.dcm'''</tt> are in the [http://medical.nema.org/ DICOM] [[Diffusion MRI|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]].
Files ending in <tt>'''.ima'''</tt> or <tt>'''.dcm'''</tt> are in the [http://medical.nema.org/ DICOM] [[Diffusion MRI#File Formats |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]].


== Matlab ==
You can confirm that you're dealing with DICOM data by running the following two commands:
Matlab has [http://www.mathworks.com/company/newsletters/digest/nov02/dicom.html extensive built-in support] for DICOM header and image data I/O with the [http://www.mathworks.com/access/helpdesk/help/toolbox/images/dicominfo.html <code>dicominfo</code>], [http://www.mathworks.com/access/helpdesk/help/toolbox/images/dicomread.html <code>dicomread</code>], and [http://www.mathworks.com/access/helpdesk/help/toolbox/images/dicomwrite.html <code>dicomwrite</code>] 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]].
<pre>
strings <SUSPECTED_DICOM_FILE> | grep -i "dicom"
strings <SUSPECTED_DICOM_FILE> | grep -i "dcim"
</pre>
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 <tt>.ima</tt> or <tt>.dcm</tt> 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 <tt>tar</tt> utility. If your presumed DICOM file seems a little funky, it might actually be a "tarball" (as the result of a <tt>tar</tt> concatenation is called) of DICOMs. Here's how to check:
<pre>tar -tf <SUSPECTED_DICOM_FILE></pre>
If you get non-error output, especially a list of <tt>*.dcm</tt> or <tt>*.ima</tt> filenames, then you're dealing with a tarball of DICOMs. Extract the original images as follows:
<pre>tar -xf <SUSPECTED_DICOM_FILE></pre>
 
The tarball may also have been compressed after concatenation; in which case you would need the <tt>-z</tt> option in the above commands:
<pre>
tar -tzf <SUSPECTED_DICOM_FILE>
tar -xzf <SUSPECTED_DICOM_FILE>
</pre>


== Mosaic ==
=== Mosaic ===
One 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.
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 ===
==== Code ====
The following scripts to handle DICOM mosaic files can be found in <tt>[file:///map/gfx0/common0/diffusion/Interface/bin/data/ /map/gfx0/common0/diffusion/Interface/bin/data/]</tt>:
The following scripts to handle DICOM mosaic files can be found in <tt>[file:///map/gfx0/common0/diffusion/Interface/bin/data/ /map/gfx0/common0/diffusion/Interface/bin/data/]</tt>:
* <tt>processMosaics.m</tt> --- split all mosaic files matching a given pattern into DICOM and [[MRIimage]] files
* <tt>processMosaics.m</tt> --- split all mosaic files matching a given pattern into DICOM and [[MRIimage]] files
Line 13: Line 36:
* <tt>writeMosaicSlices.m</tt> --- write a collection of Matlab data volumes to DICOM and [[MRIimage]] files
* <tt>writeMosaicSlices.m</tt> --- write a collection of Matlab data volumes to DICOM and [[MRIimage]] files
All of these can be launched non-interactively with <tt>matlabLauncher.py</tt>.
All of these can be launched non-interactively with <tt>matlabLauncher.py</tt>.
== Matlab ==
Matlab has [http://www.mathworks.com/company/newsletters/digest/nov02/dicom.html extensive built-in support] for DICOM header and image data I/O with the [http://www.mathworks.com/access/helpdesk/help/toolbox/images/dicominfo.html <code>dicominfo</code>], [http://www.mathworks.com/access/helpdesk/help/toolbox/images/dicomread.html <code>dicomread</code>], and [http://www.mathworks.com/access/helpdesk/help/toolbox/images/dicomwrite.html <code>dicomwrite</code>] 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 ==
== Useful Links ==

Revision as of 23:50, 1 July 2009

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