Skip to content

Instantly share code, notes, and snippets.

@jenkspt
Created July 9, 2018 18:22
Show Gist options
  • Save jenkspt/b89ff327ab0696c791fd91a394b6f8f4 to your computer and use it in GitHub Desktop.
Save jenkspt/b89ff327ab0696c791fd91a394b6f8f4 to your computer and use it in GitHub Desktop.
def crop_center(image, crop_size):
""" Crops the central region of the image with shape crop_size"""
shape = image.shape
start0 = shape[0]//2-(crop_size[0]//2)
start1 = shape[1]//2-(crop_size[1]//2)
return img[start0:start0+crop_size[0],start1:start1+crop_size[1]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment