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

**URL:** https://discourse.slicer.org/t/vtkmrmlsegmentationnode-unable-to-load-mha-file-as-a-segmentation-node/13742
**Category:** Support
**Created:** [September 29, 2020, 10:07am UTC](https://discourse.slicer.org/t/vtkmrmlsegmentationnode-unable-to-load-mha-file-as-a-segmentation-node/13742 "2020-09-29T10:07:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![strider\_hunter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/strider_hunter/32/8253_2.png) [@strider\_hunter](https://discourse.slicer.org/u/strider_hunter)
#### Post date: [September 29, 2020, 10:07am UTC](https://discourse.slicer.org/t/vtkmrmlsegmentationnode-unable-to-load-mha-file-as-a-segmentation-node/13742/1 "2020-09-29T10:07:19Z")

</div>

- 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](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/3/33d6eee19cc5e86c5589cf5527ff0f060ed048ca.png)

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](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/9/49caa05c7ecd61fd28eb908b60050be36f281973.png)

But I can do so for a _.nrrd_ file (image below)

 ![nrrd_as_segmentationode](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/7/57dd4eb0e1c0fef52c73b6a8d5ee87d24c15998e.png)

The files are from an open dataset [MICCAI2015](http://www.imagenglab.com/wiki/mediawiki/index.php?title=2015_MICCAI_Challenge)

---

<div class="post-metadata">

### Author: ![strider\_hunter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/strider_hunter/32/8253_2.png) [@strider\_hunter](https://discourse.slicer.org/u/strider_hunter)
#### Post date: [September 29, 2020, 10:28am UTC](https://discourse.slicer.org/t/vtkmrmlsegmentationnode-unable-to-load-mha-file-as-a-segmentation-node/13742/2 "2020-09-29T10:28:53Z")

</div>

- I just found [documentation](https://github.com/Slicer/Slicer/blob/master/Docs/user_guide/modules/segmentations.md#import-an-existing-segmentation-from-volume-file) which states that only NRRD/NIFTI files can be directly loaded as segmentations. Is there a particular reason for this choice? Are there plans to add more file formats?

- I was also able to find a python binding for [“Convert labelmap to segmentation node”](https://github.com/Slicer/Slicer/search?q=%22Convert+labelmap+to+segmentation+node%22) from [the slicer forum](https://discourse.slicer.org/t/how-to-automatically-convert-a-labelmap-volume-to-a-segmentation-node-upon-loading-labelmap-volume/9931/8)

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

```

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 29, 2020, 12:23pm UTC](https://discourse.slicer.org/t/vtkmrmlsegmentationnode-unable-to-load-mha-file-as-a-segmentation-node/13742/3 "2020-09-29T12:23:45Z")

</div>

> [@strider\_hunter](#):
>
> NRRD/NIFTI files can be directly loaded as segmentations. Is there a particular reason for this choice? Are there plans to add more file formats?

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](https://github.com/Slicer/Slicer/blob/master/Applications/SlicerApp/Testing/Python/SlicerScriptedFileReaderWriterTest.py)).
