在Sitk.ReadImage()中应如何使用参数?

时间:2019-01-16 11:20:49

标签: simpleitk

我正在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.

1 个答案:

答案 0 :(得分:0)

如果要使用Unix样式的路径,则需要一个斜杠,因此文件路径应为:     “ /C/Users/LENOVO/Desktop/Brats18_2013_1_1_t1.nii /”

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