0

我正在python(Windows)中的.nii文件中进行N4偏差校正。为此,我正在使用SimpleITK。在输入图像时,我在读取文件时遇到问题。

代码 :

 print("N4 bias correction runs.")
 inputImage =sitk.ReadImage("C/Users/LENOVO/Desktop/Brats18_2013_1_1_t1.nii")
 maskImage = sitk.OtsuThreshold(inputImage,0,1,200) 
 sitk.WriteImage(maskImage,"C/Users/LENOVO/Desktop/Brats18_2013_1_1_t1_Mask.nii")
 inputImage = sitk.Cast(inputImage,sitk.sitkFloat32)

 corrector = sitk.N4BiasFieldCorrectionImageFilter();

 output = corrector.Execute(inputImage,maskImage)
 sitk.WriteImage(output,"C/Users/LENOVO/Desktop/Brats18_2013_1_1_t1_Mask.nii")
 print("Finished N4 Bias Field Correction.....")

错误 :

RuntimeError                             
 Traceback (most recent call last)
<ipython-input-26-0835d7f75708> in <module>()
      1 
      2 print("N4 bias correction runs.")
----> 3 inputImage = sitk.ReadImage("C/Users/LENOVO/Desktop/Brats18_2013_1_1_t1.nii")
      4 
      5 maskImage = sitk.OtsuThreshold(inputImage,0,1,200)

~\Anaconda3\lib\site-packages\SimpleITK\SimpleITK.py in ReadImage(*args)
   8612 
   8613     """
-> 8614     return _SimpleITK.ReadImage(*args)
   8615 class HashImageFilter(ProcessObject):
   8616     """

RuntimeError: Exception thrown in SimpleITK ReadImage: C:\Users\dashboard\Miniconda3\conda-bld\simpleitk_1521730316398\work\Code\IO\src\sitkImageReaderBase.cxx:89:
sitk::ERROR: The file "C/Users/LENOVO/Desktop/Brats18_2013_1_1_t1.nii" does not exist.
4

1 回答 1

0

如果您要使用 Unix 风格的路径,那么您需要一个前导斜杠,因此文件路径应该是:“/C/Users/LENOVO/Desktop/Brats18_2013_1_1_t1.nii/”

或者你可以使用 Windows 风格的路径,那么它将是:“c:\Users\LENOVO\Desktop\Brats18_2013_1_1_t1.nii”

于 2019-01-16T16:06:30.547 回答