我正在寻找最有效的图像调整大小方法。如果图像相对较小(例如3000x2000),则PIL的效果很好,但如果分辨率很高(16000x12000),处理时间会很长。图像不必看起来漂亮,我是为了比较而调整它们的大小,以查找具有nrmse的图像副本。
from PIL import Image
img1 = Image.open("img1.jpg")
img2 = Image.open("img2.jpg")
print img1.size
print img2.size
# add width to height to see which resolution is bigger
im1s = img1.size[0] + img1.size[1]
im2s = img2.size[0] + img2.size[1]
# if both images are bigger than 3000 pixels make them smaller for comparison
if im1s > 3000 and im2s > 3000:
print("Width and height of both images is bigger than 3000 pixels resizing them for easier comparison")
im1_resize = img1.resize((640, 480), Image.ANTIALIAS)
im2_resize = img2.resize((640, 480), Image.ANTIALIAS)
im1_resize.save('im1r.jpg')
im2_resize.save('im2r.jpg')