For a project that I am working on I have to resize a lot of nrrd's. These files are stored in a very specific order and should also be returned to the same file.
For the last few days I have been trying different ways to open the image, resize it and save it in the correct location. So far, I have not come past the opening and resizing, let alone the saving.
I have tried the following code:
PATH = "H:\Honours\Code\TestingOutcome\Resize testing\old_size_images\\"
Copy_to_path="H:\Honours\Code\TestingOutcome\Resize testing\resized_images\\"
for filename in os.listdir(PATH):
img = Image.open(os.path.join(PATH, filename))
img = Image.resize((256,256), Image.ANTIALIAS)
img.save(Copy_to_path+filename+'.nrrd')
However the issue here is that this code gives me a permission error due to the abnormal file structure.
PermissionError: [Errno 13] Permission denied: 'H:\Honours\Code\TestingOutcome\Resize testing\old_size_images\BrainMets-UCSF-01261_Target 4_10'
The error is caused by the fact that old_size_images is folder, containing folders which contain the images. I do not know how to acces this folder and the images in there, resize them and save them in a similar structure.
The issue here is that the images that have to be resized are saved in files with variants of this name BrainMets-UCSF-01261_Target 4_10.
Is there any way that I can open these files, resize the images in there, save the images in the same file and then continue to the next? The most important struggle at this moment how to get into and out of the specific file while continuing to go through them?