demo_ctn / cv_utils.py
zoanhy's picture
Upload 35 files
2b5ebe9 verified
raw
history blame contribute delete
483 Bytes
import cv2
import numpy as np
def resize_image(input_image, resolution, interpolation=None):
H, W, C = input_image.shape
H = float(H)
W = float(W)
k = float(resolution) / max(H, W)
H *= k
W *= k
H = int(np.round(H / 64.0)) * 64
W = int(np.round(W / 64.0)) * 64
if interpolation is None:
interpolation = cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA
img = cv2.resize(input_image, (W, H), interpolation=interpolation)
return img