[vtkMRMLSegmentationNode] Unable to load .mha file as a segmentation node

  • I have a file which is originally .nrrd but I convert it to .mha (for homogeneity purposes as I use other datasets as well)
  • I am able to load the .nrrd file using slicer.util.loadSegmentation(pathMaskFile), but unable to do the same via the .mha file. The content/dimensions are the same, but the header formatting is of course different.
    ** The error is in slicer\util.py", line 598, in loadNodeFromFile()
  • The headers of my files are in the image below
    nrrd_vs_mha_for_maskfile

Is there any way to change the header of the .mha file so that it directly loads as a segmentation node ? I am also not able to do via the drag-and-drop UI option (image below)

mha_volume_only

But I can do so for a .nrrd file (image below)
nrrd_as_segmentationode

The files are from an open dataset MICCAI2015

tmp = slicer.util.loadLabelVolume(pathMaskFile)
mask = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLSegmentationNode')
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(tmp, mask)
slicer.mrmlScene.RemoveNode(tmp)

We encourage users to use NRRD format for segmentation storage (as it allows simple storage of additional metadata). Nifti is widely used by the neuroimaging community and many people requested support for it, so we enabled it, too. We don’t plan to add direct support for any other formats, as you it just takes two clicks or 2-3 lines of Python code to convert a labelmap volume to segmentation.

Metaimage (mha) format capabilities are almost identical to NRRD, but it has a huge limitation: 4D data support in metaimage is not robust. You cannot specify meaning of each dimension, which means that it cannot store overlapping segmentations or time sequences reliably. Its format also specifies a few exotic features (such as multi-file headers), which are not commonly implemented, and image orientation definition is somewhat misleading.

You can extend/customize almost anything using Python or C++ plugins. If you want to add import/export of any file formats as any node type then you can do it by specifying a file reader for it (just an extra class in your Python scripted module, about 10-20 lines, see example).