mirror of
https://github.com/Laurent2916/REVA-QCAV.git
synced 2024-11-08 22:42:02 +00:00
c8c82204bf
slow, no gpu, no validation
25 lines
542 B
Python
25 lines
542 B
Python
import PIL
|
|
|
|
def split_into_squares(img):
|
|
"""Extract a left and a right square from ndarray"""
|
|
"""shape : (H, W, C))"""
|
|
h = img.shape[0]
|
|
w = img.shape[1]
|
|
|
|
|
|
left = img[:, :h]
|
|
right = img[:, -h:]
|
|
|
|
return left, right
|
|
|
|
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
|