在jupyter notebook(python)中工作,我需要将1,478个图像更改为一个常见大小。我很困惑如何选择一个适用于所有图像的尺寸。我尝试了下面的方法,它减少了大约12种不同尺寸的裁剪到这4种尺寸{(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)