mirror of
https://github.com/Laurent2916/REVA-QCAV.git
synced 2024-11-09 23:12:05 +00:00
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
|