Search code examples
c++dicomitkgdcm

Image Position/Orientation not written when saving itkImage as DICOM


I have a 3D volume as itkImage<unsigned char, 3> and want to save it as DICOM series. Saving the series works so far, but the metadata tags "Image Position Patient" and "Image Orientation Patient" are not saved in the dicom file. All other tags are saved correctly.

If I print the metadata dictionary to the console these tags are printed correctly. When I open the files in ITK-SNAP these two tags are missin.

0010|0010 Patient

0010|0020 12345

0020|0032 0\0\0

0020|0037 1\0\0\0\1\0

This is the part of the code where these tags are stored in the metadata. I created a gist with a working example.

UC3ImageType::PointType position;
UC3ImageType::IndexType index;
index[0] = 0;
index[1] = 0;
index[2] = f;
image->TransformIndexToPhysicalPoint(index, position);
value.str("");
value << position[0] << "\\" << position[1] << "\\" << position[2];
itk::EncapsulateMetaData<std::string>(*dictionary, "0020|0032", value.str());
value.str("");
value << position[2];
itk::EncapsulateMetaData<std::string>(*dictionary, "0020|1041", value.str());

itk::EncapsulateMetaData<std::string>(*dictionary, "0020|0037", "1\\0\\0\\0\\1\\0");

What's wrong with this code? Are there other tags that are required, such that these tags are saved as well?


Solution

  • I could solve the problem by specifying a different SOP Class UID. By default it's using Secondary Capture IOD and I changed it to Ultrasound Multi Frame, which is also more apropriate for my image. Now the Image Orientation/Position are stored correctly.

    const std::string SOP_CLASS_UID = "0008|0016";
    const std::string US_MULTIFRAME_UID = "1.2.840.10008.5.1.4.1.1.3.1";
    itk::EncapsulateMetaData<std::string>(*dictionary, SOP_CLASS_UID, US_MULTIFRAME_UID);
    

    However, to me it's still strange, that there is no warning or exception when a metadata tag is not saved due to whatever reason.