Skip to content

Instantly share code, notes, and snippets.

@zborowa
Created May 29, 2015 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zborowa/ad7f18ef86764932630e to your computer and use it in GitHub Desktop.
Save zborowa/ad7f18ef86764932630e to your computer and use it in GitHub Desktop.
Python resize and center array image
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