Created
May 29, 2015 03:28
-
-
Save zborowa/ad7f18ef86764932630e to your computer and use it in GitHub Desktop.
Python resize and center array image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def resize_image(img): | |
"""Return a resized image. | |
:param img: | |
""" | |
cropped_image = crop_image(img) | |
if len(cropped_image) >= len(cropped_image[0]): | |
percent = (1.0 - (float(len(cropped_image)) / float(len(img)))) * float(len(img)) | |
else: | |
percent = (1.0 - (float(len(cropped_image[0])) / float(len(img)))) * float(len(img)) | |
axis0 = float(len(cropped_image)) + percent | |
axis1 = float(len(cropped_image[0])) + percent | |
scaled_image = transform.resize(img, (axis0, axis1)) | |
padded_image = pad_image(img, scaled_image) | |
return img_as_uint(padded_image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment