How do you access the "Modality" metadata from the MHA header?

Some MHAs contain a “Modality” tag, which seems to be treated differently than other keys. How do we access it?

Some sort of MWE:

> cat /tmp/test.mha
ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
CompressedData = False
TransformMatrix = 1 0 0 0 1 0 0 0 1
Offset = 0 0 0
CenterOfRotation = 0 0 0
AnatomicalOrientation = RAI
ElementSpacing = 1 1 1
CustomMeta = CustomValue
DimSize = 2 2 2
ElementType = MET_DOUBLE
Modality = CT
ElementDataFile = LOCAL


python -c "import SimpleITK as sitk
           img = sitk.ReadImage('/tmp/test.mha')
           print(img.GetMetaDataKeys())
           print(img.GetModality())"
('CustomMeta', 'ITK_InputFilterName', 'ITK_original_direction', 'ITK_original_spacing')
Traceback (most recent call last):
  File "<string>", line 4, in <module>
AttributeError: 'Image' object has no attribute 'GetModality'

Is this field just dropped or do my doc-searching skills needs improving?

Hello @nicoco,

Welcome to the ITK community. Your doc-searching skills and bug finding skills are good as they are!

Hopefully, this pull request will resolve the issue.

1 Like