0

Working in jupyter notebook (python), I have 1,478 images that I need to change to one common size. I'm confused as to how to do pick one size that works for all images. I tried the method below, and it reduced a crop of about 12 different sizes to these 4 sizes {(3120, 4160) (2340, 4160) (3264, 2448) (3264, 2441)}

i = 0
for filepath in all_cervix_images['imagepath']:
    print(i)
    i +=1
    width, height = Image.open(filepath).size
    #maxsize = 3264, 4160
    ratio = min(3264/width, 4160/height)
    size = int(width * ratio), int(height * ratio)
    try:
        img = Image.open(filepath)
        img = img.resize(size, Image.ANTIALIAS)
        img.save(filepath)
    except IOError:
        print ("cannot create thumbnail for %s" % filepath)
  • Have you made any attempt at all? Like changing one image for example? – Mad Physicist Feb 26 '18 at 19:00
  • Yes, I used this method (https://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio) (maxsize = 3264, 4160) on all of the images , and the sizes in the array changed to (3120, 4160) (2340, 4160) (3264, 2448) (3264, 2441) – keerat singh Feb 28 '18 at 18:44
  • There is no code in your question. Please do not post code in the comments. Include *all* relevant information in the question, including your attempts and any ideas you may have. – Mad Physicist Feb 28 '18 at 19:23
  • I updated my post. Sorry, I'm new to asking questions on Stack Overflow. – keerat singh Mar 08 '18 at 18:51
  • Nothing wrong with being new to this. Thanks for responding. At least now I know what the pictures are of :) – Mad Physicist Mar 08 '18 at 19:46

0 Answers0