Skip to content

Instantly share code, notes, and snippets.

@daviddao
Created April 11, 2016 19:12
Show Gist options
  • Save daviddao/f734b541a8c603df08206a7ab7062df3 to your computer and use it in GitHub Desktop.
Save daviddao/f734b541a8c603df08206a7ab7062df3 to your computer and use it in GitHub Desktop.
'''
Takes an image in numpy format as input and returns a padded image
'''
def pad_image(image, output_shape):
x_pad = (output_shape[0] - image.shape[0]) / 2
y_pad = (output_shape[1] - image.shape[1]) / 2
resized = np.pad(image, ((x_pad,x_pad),(y_pad,y_pad)), mode='constant', constant_values=0)
return resized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment