ImageGear for C and C++ on Windows v20.1 - Updated
Read Data Elements
User Guide > How to Work with ... > Formats with Additional Functionality > DICOM > DICOM Metadata > Read Data Elements

The key functions that allow access to Data Elements, or metadata, in a DICOM image include:

Function Description

MED_DCM_DS_exists 

Determines if a DICOM image has data elements.

MED_DCM_DS_info_get

Returns the number of data elements in the DICOM image, and the maximum SQ (hierarchy) level.

MED_DCM_DS_curr_info_get

Returns information about the current data element, including tag name (enumIGMedTag), data type (enumIGMedVR), and size.

MED_DCM_DS_move_*

The "move" functions move the current data element pointer to a new tag; an example function is MED_DCM_DS_move_find. Note that MED_DCM_DS_move_first must be called before iterative move functions such as MED_DCM_DS_move_next.

MED_DCM_DS_curr_data_get

Returns the current data element's data, and size of data returned.

MED_DCM_DS_curr_data_get_string

Returns the current data element's data as a string.

For a complete list, see Data Set Functions.

These functions will allow querying a DICOM image for existence of tags, lookup of a tag by name, tag iteration, and retrieval of tag data. Alternatively, to write data tags, see Writing Data Elements.

This topic provides information about how to do the following:

Search for a Tag

The follow snippet will demonstrate how to find a tag by name (example: patient name) in a DICOM image, and update the data pointer to the tag accordingly.

C and C++
Copy Code
BOOL was_found;
AT_DCM_TAG tag = DCM_TAG_PatientsName;
MED_DCM_DS_move_find(myDicomImage, MED_DCM_MOVE_LEVEL_FLOAT, tag, NULL, NULL, NULL, NULL, &was_found);
if (was_found)
{
    // Process tag here. e.g, MED_DCM_DS_curr_data_get_string ( … )
}

Read All Tags in a DICOM Image

The following snippet sequentially reads all tags in a DICOM image. First, call MED_DCM_DS_move_first to position the data pointer to the first tag. Next, MED_DCM_DS_move_next can be used to iterate through each tag, and keep track of how many tags remain. For each tag, MED_DCM_util_tag_info_get is used to retrieve its name.

C and C++
Copy Code
void PrintAllDicomDataElements(HIGEAR dicomImage)
{
   //Check if the image has tags
   BOOL hasDataElements;
   MED_DCM_DS_exists(dicomImage, &hasDataElements);
   if (hasDataElements == FALSE)
   {
       printf("Image has no data elements");
       return;
   }

   printf("Dicom Tags:\n");

   //Use MED_DCM_DS_move_next to loop through each tag and print information
   char elementData[100];
   char tagName[100];
   AT_DCM_TAG tag = 0;
   LONG numberOfElementsRemaining = 0;
   MED_DCM_DS_info_get(dicomImage, &numberOfElementsRemaining, NULL);
   MED_DCM_DS_move_first(dicomImage, MED_DCM_MOVE_LEVEL_FLOAT, &tag, NULL, NULL, NULL, NULL);
   while (numberOfElementsRemaining > 0)
   {
       MED_DCM_util_tag_info_get(tag, NULL, NULL, NULL, tagName);
       MED_DCM_DS_curr_data_get_string(dicomImage, elementData, sizeof(elementData));
       printf("%s -> %s\n", tagName, elementData);

       MED_DCM_DS_move_next(dicomImage, MED_DCM_MOVE_LEVEL_FLOAT, &tag,
               NULL, NULL, NULL, NULL, &numberOfElementsRemaining);
   }
}
Is this page helpful?
Yes No
Thanks for your feedback.