0

I have been trying to resize images (specifically nrrd files)

I tested the following code on normal JPEG and PNG files and it works.

data_path = r'H:\User\Code\TestingData\TestData'
path_open_patients = glob.glob(data_path + '//' + '*')
for patient in tqdm.tqdm(path_open_patients): 
    dirs = os.listdir(patient)
    for item in dirs:
        if os.path.isfile(patient +'\\'+ item):
            im = Image.open(patient +'\\'+ item)
            f, e = os.path.splitext(patient +'\\'+ item)
            imResize = im.resize((256,256), Image.ANTIALIAS)
            imResize.save(f + ' _resized.nrrd', 'nrrd')
        if not os.path.isfile(patient+item):
            print('you lose')

Unfortunately this gives me the following error: "UnidentifiedImageError: cannot identify image file 'H:\User\Code\TestingData\TestData\BrainMets-UCSF-01261_Target 1_7\image.nrrd'

I do not want to convert the nrrd's to JPEG because this might ruin the quality of the image? Are there any other options?

0 Answers0