Sorting DICOM imagaes

Skip to first unread message

MJ Stoutjesdijk

Jan 3, 2001, 2:51:12 AM1/3/01

I wonder which tactic I should use to sort DICOM images in recording order.
I found that image number is not foolproof, nor is SOP Instance UID for
Is there a tag that would _always_ work, even with images from machines
that were at some point not _quite_ compliant to the standard?


Mark J. Stoutjesdijk, M.D., M.Sc. | Tel. +31-24-3614545
University Medical Center St. Radboud | Fax. +31-24-3540866
Dept. of Diagnostic Radiology |
P.O. Box 9101 |
6500 HB Nijmegen, The Netherlands |

David Clunie

Jan 3, 2001, 9:12:46 AM1/3/01
Hi Mark

The short answer is no, there is no single tag.

The question is what do you mean by "recording order" ? The order
in which the images were received by the SCP (arbitrary), the order
in which the images were reconstructed from the raw data (not necessarily
useful), the order in which the raw data from which they were reconstructed
was acquired (may be the same for all slices in a pulse sequence in MR).

To sort things by a temporal parameter, you have two sets of attributes
to consider, Content (formerly Image) Date & Time, and Acquisition Date
and Time. Vendors between and within themselves on which is used to
describe when the raw (source) data was acquired, and some experimentation
is required to pick the right for your purpose.

A better question is why do you care and is there a better parameter to
sort on ? Certainly for dynamic contrast studies the temporal order of
acquisition is important, but for "static" studies the question often
arises as to how to best present slices through a volume to a user, and
the answer is usually by anatomical location. The order in which slices
are acquired is often essentially irrelevant, but is used as a poor man's
substitute for sorting by location. For example, I like to see my axial
heads from foot (base of skull) to head (vertex); I don't care if they
were acquired in that order, simultaneously, or if one acquisition went
one directuion and a second the opposite. Accordingly I sort along a vector
normal to the plane of the image (determined from Image Orientation (Patient))
by the value of Image Position (Patient) projected onto that vector. These
are mandatory attributes that are reliably filled in by all CT and MR

I avoid using the optional informative Slice Location since it's sign and
direction are undefined and arbitrary.

In all this, I haven't mentioned Instance (formerly Image) Number, because
so many vendors don't fill it in, or always set it to 1 for the whole
acquisition, etc. If it is filled in, it is often a reliable indicator
of the order in which slices were reconstructed (but not necessarily
acquired), when Content (Image) Time and Acquisition Time fail.

You may also need to separate out multiple slices at the same location
that some vendors put in the same series, such as dual echo long TR
sequences in MR (most vendors), or different recon kernels in CT (I
think Toshiba does or used to do this). I.e. you may have to use a
major sort key of Echo Time or Convolution Kernel and a minor sort
key of position (derived as described above), or the other way around
depending on whether you want to view the different kinds of slices
sequentially or interleaved (consistently).

You may be interested in my dcsort utility, which provides the ability
to sort by any (numeric) attribute, and handles the position/orientation
sorting described above as a special case.

Note also that in pre-DICOM (e.g. SPI files) and even in DICOM files,
there are a host of retired and private attributes that one may care
to try to sort on to get a particular result (e.g. the old ACR-NEMA
Location which was replaced by Slice Location, not sure why; the Philips
private Slice Number tag, and so on).


David A. Clunie
Development Director, Medical Imaging Products
ComView Corporation Work 914-332-4800 Fax 208-445-5867
220 White Plains Road, 5th Floor Home 570-897-7123 Fax 570-897-5117
Tarrytown NY 10591

dee csipo

Jan 3, 2001, 11:27:58 PM1/3/01

I assume that you want to sort your MR and CT images :-).  For those the best method is to sort by  the spatial coordinates in the direction of the image plane normals.  You can get the upper left hand coordinates from 0020,0032 and the row and column cosines from 0020,37.  You can create the homogenius transform matrix by

| RowCosX,   RowCosY,    RowCosZ,   0    |
| ColCosX,   ColCosY,    ColCosZ,   0    |
| NrmX,      NrmY,       NrmZ,      0    |
| 0,         0,          0,         1    |

You can create the normals by

bool Slice::_fCheckOneVector(double CosX, double CosY, double CosZ)
 // Check if the vector passed is a unit vector
 if (fabs(CosX*CosX+CosY*CosY+CosZ*CosZ-1) < 0) {
  return (false);
 } else {
  return (true);


bool Slice::_fMakeNormalVector()
 _mNormCosX = _mRowsCosY * _mColsCosZ - _mRowsCosZ * _mColsCosY;
 _mNormCosY = _mRowsCosZ * _mColsCosX - _mRowsCosX * _mColsCosZ;
 _mNormCosZ = _mRowsCosX * _mColsCosY - _mRowsCosY * _mColsCosX;
 return (_fCheckOneVector(_mNormCosX, _mNormCosY, _mNormCosZ));


Pick the largest ABS value of the normals.

Sort the images having the frame of reference UIDs that are the same type (Localizers or axial)

Good Luck


Reply all
Reply to author
0 new messages