前言
有些nii
/nii.gz
的文件在使用simpleITK读取时会遇到ITK only supports orthonormal direction cosines
的错误,这个时候就需要进行修复
代码
file_path = "001.nii.gz"
try:
image = sitk.ReadImage(file_path)
except:
print(f'cosines problem occures, try to fix it...')
img = nib.load(file_path)
qform = img.get_qform()
img.set_qform(qform)
sform = img.get_sform()
img.set_sform(sform)
nib.save(img,file_path)
image = sitk.ReadImage(file_path)
print(f'now we have fixed it!')
print(image.GetSize())