def zoom_image_fixed_size(image, zoom):
"""Return rescaled and cropped image array.
"""
if zoom < 1:
raise ValueError("Zoom scale factor must be at least 1.")
elif zoom == 1:
# copy
return np.array(image)
width, height = image.shape
t_width = int(np.ceil(zoom*width))
t_height = int(np.ceil(zoom*height))
if t_width//2 != width//2:
t_width -= 1
if t_height//2 != height//2:
t_height -= 1
t_image = transform.resize(image, (t_width, t_height), order=3)
return t_image[(t_width-width)/2:(t_width+width)/2,
(t_height-height)/2:(t_height+height)/2]
评论列表
文章目录