-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreshape_img.py
28 lines (26 loc) · 868 Bytes
/
reshape_img.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import cv2
def image_resize(image, width = None, height = None, inter = cv2.INTER_AREA):
dim = None
(h, w) = image.shape[:2]
# if both the width and height are None, then return the
# original image
if width is None and height is None:
return image
# check to see if the width is None
elif width is None:
# calculate the ratio of the height and construct the
# dimensions
r = height / float(h)
dim = (int(w * r), height)
# otherwise, the height is None
elif height is None:
# calculate the ratio of the width and construct the
# dimensions
r = width / float(w)
dim = (width, int(h * r))
else :
dim=(width,height)
# resize the image
resized = cv2.resize(image, dim, interpolation = inter)
# return the resized image
return resized