def resize_to_optimal(infile, scale_ratio, rect, outfile):
image_array = imread(infile, mode='RGB')
im_shape = image_array.shape
h, w, _ = im_shape
width = float(rect.right()-rect.left())
scale_amount = (optimal_extent * scale_ratio) / width
new_w = int(scale_amount * w)
new_h = int(scale_amount * h)
new_w = new_w - (new_w % 4)
new_h = new_h - (new_h % 4)
print("optimal resize of width {} and ratio {} went from {},{} to {},{}".format(width, scale_ratio, w, h, new_w, new_h))
new_shape = (new_h, new_w)
image_array_resized = imresize(image_array, new_shape)
imsave(outfile, image_array_resized)
return new_shape
评论列表
文章目录