I want to convert .mnc files from BrainWeb (https://brainweb.bic.mni.mcgill.ca/brainweb/anatomic_normal_20.html) to .mha file format for use in TumorSim (https://www.nitrc.org/projects/tumorsim/).
I have tried converting the file from .mnc to .nii using nibabel and mnc2nii, and then converting the .nii file to the .mha format.
However, this process leads to the file size increasing dramatically (from 56.9 MB .mha to 56.9~227.5 MB .nii depending on output voxel format)
From there, converting the .nii file to the .mha format retains the same file size. The size of .mha files used in TumorSim are around 4.8 MB.
Objective: I want a 1 step solution to convert .mnc files to .mha files
Code:
import SimpleITK as sitk
inputImageFileName = 'subject04_wm_v.mnc'
outputImageFileName = 'white_matter.mha'
reader = sitk.ImageFileReader()
reader.SetImageIO("MINCImageIO")
reader.SetFileName(inputImageFileName)
image = reader.Execute()
writer = sitk.ImageFileWriter()
writer.SetFileName(outputImageFileName)
writer.Execute(image)
Output:
(py3env) russ@russ-Latitude-E5450:~/Documents/Testing_Space/ITK$ python mncconverter.py
/tmp/SimpleITK-build/ITK/Modules/ThirdParty/MINC/src/libminc/libsrc2/volume.c:1399 (from MINC): Unable to open file 'subject04_wm_v.mnc'
Traceback (most recent call last):
File "mncconverter.py", line 9, in <module>
image = reader.Execute()
File "/home/russ/Documents/freesurfer/psacnn_brain_segmentation/py3env/lib/python3.6/site-packages/SimpleITK/SimpleITK.py", line 8654, in Execute
return _SimpleITK.ImageFileReader_Execute(self)
RuntimeError: Exception thrown in SimpleITK ImageFileReader_Execute: /tmp/SimpleITK-build/ITK/Modules/IO/MINC/src/itkMINCImageIO.cxx:322:
itk::ERROR: MINCImageIO(0x2de7600): Could not open file "subject04_wm_v.mnc".