I want to read through images in different folders. I wrote the following code
for Case_id in range(1,6):
path ='/Users/XXXXXX/Desktop/pyradiomics/Converted/Case{}/'.format(Case_id)
print(path)
for files in os.listdir(path):
if files.endswith("Image.nii"):
print(files)
image=sitk.ReadImage (files)
if files.endswith("label.nii"):
print(files)
mask=sitk.ReadImage (files)
When I run this I get an error message:
RuntimeError: Exception thrown in SimpleITK ReadImage: /scratch/dashboard/SimpleITK-OSX10.6-x86_64-pkg/SimpleITK/Code/IO/src/sitkImageReaderBase.cxx:89:
sitk::ERROR: The file "xxxx_image.nii" does not exist.
If I just run the print command I can see all the files along with path in the specified folder. Would appreciate the help.