Let\'s say I have a numpy image of some width x and height y. I have to crop the center portion of the image to width cropx and height cropy. Let\'s assume that cropx and cr
Another simple modification from @Divakar's answer to preserve color channels:
def crop_center(img,cropx,cropy): y,x,_ = img.shape startx = x//2-(cropx//2) starty = y//2-(cropy//2) return img[starty:starty+cropy,startx:startx+cropx,:]