MedicalVisualization

DCMTK Keys

DCMTK | | Introduction to ITK

DCMTK also offers access to the meta data of each image specified by a particular standardized DCMTK key via:

image->findAndGetOFString(key, ...);

Common DCMTK keys are

  • DCM_Columns, DCM_Rows
  • DCM_PixelSpacing
  • DCM_SmallestImagePixelValue
  • DCM_LargestImagePixelValue
  • DCM_PatientName
  • DCM_ImagePositionPatient

Each DCM key is represented by two numbers (g, e), a 16-bit group number g and a 16-bit element number e. The two numbers are known as DICOM tag.

For example, the patient’s name, as given by the DCMTK key DCM_PatientName, corresponds to the DICOM tag (0010,0010).

To read the patient name, we query for the DCM_PatientName key:

OFString name;
image->findAndGetOFString(DCM_PatientName, name));

Note: To convert from the internal dcmtk data type OFString to a std::string type we use a copy constructor:

std::string(name.c_str())

To get the dimensions of an image, we query the DCM_Columns and DCM_Rows keys:

bool getDimensions(DcmDataSet *image, long long &cols,long long &rows)
{
   OFString tmp;

   if (image->findAndGetOFString(DCM_Columns,tmp).bad()) return(false);
   sscanf(tmp.c_str(),"%lld",&cols);
   if (image->findAndGetOFString(DCM_Rows,tmp).bad()) return(false);
   sscanf(tmp.c_str(),"%lld",&rows);

   return(true);
}

Each value associated with a DCM key can have multiple fields, for example to represent a vector: To get the 3 fields for the position vector of the origin of an image (in meters), we query the DCM_ImagePositionPatient tag 3 times:

bool getPosition(DcmDataSet *image, float position[3])
{
   if (image->findAndGetOFString(DCM_ImagePositionPatient,tmp,0).bad()) return(false);
   sscanf(tmp.c_str(),"%g",&position[0]);
   if (image->findAndGetOFString(DCM_ImagePositionPatient,tmp,1).bad()) return(false);
   sscanf(tmp.c_str(),"%g",&position[1]);
   if (image->findAndGetOFString(DCM_ImagePositionPatient,tmp,2).bad()) return(false);
   sscanf(tmp.c_str(),"%g",&position[2]);

   return(true);
}


DCMTK | | Introduction to ITK

Options: