REVA-QCAV/utils.py
2017-08-17 15:32:38 +02:00

27 lines
590 B
Python

import PIL
import numpy as np
def get_square(img, pos):
"""Extract a left or a right square from PILimg"""
"""shape : (H, W, C))"""
img = np.array(img)
h = img.shape[0]
w = img.shape[1]
if pos == 0:
return img[:, :h]
else:
return img[:, -h:]
def resize_and_crop(pilimg, scale=0.5, final_height=640):
w = pilimg.size[0]
h = pilimg.size[1]
newW = int(w * scale)
newH = int(h * scale)
diff = newH - final_height
img = pilimg.resize((newW, newH))
img = img.crop((0, diff // 2, newW, newH - diff // 2))
return img