Using OpenCV python, you can do this:
import cv2
import numpy as np
# load the image
image = cv2.imread('path/to/your_image.jpg')
# define some values
patch_center = np.array([500, 450])
patch_scale = 0.23
# calc patch position and extract the patch
smaller_dim = np.min(image.shape[0:2])
patch_size = int(patch_scale * smaller_dim)
patch_x = int(patch_center[0] - patch_size / 2.)
patch_y = int(patch_center[1] - patch_size / 2.)
patch_image = image[patch_x:patch_x+patch_size, patch_y:patch_y+patch_size]
# show image and patch
cv2.imshow('image', image)
cv2.imshow('patch_image', patch_image)
cv2.waitKey()
Notice that this was done step-by-step just to be easier to understand. You can do many of these steps directly.
OpenCV
,skimage
, and alsoPIL
and purenumpy
. You should pick the library you want to use (probably based on other criteria since they can all do this), try to do it with whatever tool you pick, and then ask a question if you have trouble with that (which you probably won't). – tom10