I am trying to adjusting the header of .mha files, adding transform information into the .mha header by using a python script. But i’m facing a problem finding the correct encoding format to read and write the .mha file, and every time I got invalid output that can neither be uncompressed by VolumeReconstructor command line nor be rendered in 3D Slicer interface. Which encoding format does mha file use? and which one should I use to read and write the .mha file? Great Thank
Is this a sequence .mha file? Could you post the error(s) that you get?
Yes, I tried to adjust a .mha file of a png sequence, and after I inserted a header of transform, the .mha became unreadable.
Here is the screen shot of the .mha file with inserted header, all following the sample data format.
By the way, does EditSequenceFile.cxx in PlusCommon have the function of reading and editing png sequence? Thank you!
I don’t think it can do png sequence. The pixel data is stored as RGB, either compressed (zip) or uncompressed.
In the past I have first used ImageJ with the MetaImage plugins to load a sequence of images and then write it out into an mha (uncompressed). Then I’ve manually added the transform data into the header with notepad++
So, can I understand it in this way, that in 3D Slicer, the encoding format of mha is metadata, and only metadata, which can only be edited or added lines by plugins related to itk? Is the notepad++ you’ve mentioned also have itk plugin? Thanks!
mha is metadata and image data. itk can read metadata, but does not recognize a number of tags related to sequences.
notepad++ is just a text editor, which you can use to edit the metadata part of the file.
I’ve used the PSPad and windows txt editor before, as well as made a simple python script to edit a mha file’s header, but they all returned the error above. It seems not all text editors can do this job, due to the encoding format of mha file, I think.
It is easier to put a MetaImage into .mhd+.raw files rather than the single .mha file. Then you can edit the metadata in the .mhd file without any issues related to encoding that could corrupt the .mha.
Yeah this works good. Great thanks