def resize_sample(sample, shape=None, use_interp=True, scale=None):
if (shape and scale) or (not shape and not scale):
raise ValueError('Must specify exactly one of shape or scale, but got shape=\'{}\', scale=\'{}\''.format(shape, scale))
# Use INTER_AREA for shrinking and INTER_LINEAR for enlarging:
interp = cv2.INTER_NEAREST
if use_interp:
target_is_smaller = (shape and shape[1] < sample.shape[1]) or (scale and scale < 1) # targetWidth < sampleWidth
interp = cv2.INTER_AREA if target_is_smaller else cv2.INTER_LINEAR
if shape:
resized = cv2.resize(sample, (shape[1], shape[0]), interpolation=interp)
else:
resized = cv2.resize(sample, None, fx=scale, fy=scale, interpolation=interp)
return resized
评论列表
文章目录