我想将 BrainWeb ( https://brainweb.bic.mni.mcgill.ca/brainweb/anatomic_normal_20.html ) 中的 .mnc 文件转换为 .mha 文件格式以用于 TumorSim ( https://www.nitrc.org/项目/tumorsim/)。
我尝试使用 nibabel 和 mnc2nii 将文件从 .mnc 转换为 .nii,然后将 .nii 文件转换为 .mha 格式。
但是,此过程会导致文件大小急剧增加(从 56.9 MB .mha 到 56.9~227.5 MB .nii,具体取决于输出体素格式)
从那里开始,将 .nii 文件转换为 .mha 格式会保留相同的文件大小。TumorSim 中使用的 .mha 文件大小约为 4.8 MB。
目标:我想要一个将 .mnc 文件转换为 .mha 文件的 1 步解决方案
代码:
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)
输出:
(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".