def _resize(img, size, interpolation):
img = img.transpose((1, 2, 0))
if interpolation == PIL.Image.NEAREST:
cv_interpolation = cv2.INTER_NEAREST
elif interpolation == PIL.Image.BILINEAR:
cv_interpolation = cv2.INTER_LINEAR
elif interpolation == PIL.Image.BICUBIC:
cv_interpolation = cv2.INTER_CUBIC
elif interpolation == PIL.Image.LANCZOS:
cv_interpolation = cv2.INTER_LANCZOS4
H, W = size
img = cv2.resize(img, dsize=(W, H), interpolation=cv_interpolation)
# If input is a grayscale image, cv2 returns a two-dimentional array.
if len(img.shape) == 2:
img = img[:, :, np.newaxis]
return img.transpose((2, 0, 1))
评论列表
文章目录