Resize image keeping the ratio of width and height unchanged
Guys I'm using tensorflow and trying to train a classifier for some predefined classes.I want to resize images with keeping the ration of width and height. Do you have any implementations?
Guys I'm using tensorflow and trying to train a classifier for some predefined classes.I want to resize images with keeping the ration of width and height. Do you have any implementations?
Just use this function, which resizes the image by it's greater side.
from PIL import Image
def resize_image(img, size):
w, h = img.size
if isinstance(size, int):
if h < w:
new_h, new_w = size * h / w, size
else:
new_h, new_w = size, size * w / h
else:
new_h, new_w = size
new_h, new_w = int(new_h), int(new_w)
new_image = img.resize((new_w, new_h), Image.BILINEAR)
return new_image