I have an image im
which is an array as given by imread
. Say e.g.
im = np.array([[1,2,3,4],
[2,3,4,5],
[3,4,5,6],
[4,5,6,7]]
I have another (n,4)
array of windows
where each row defines a patch of the image as (x, y, w, h)
. E.g.
windows = np.array([[0,0,2,2],
[1,1,2,2]]
I'd like to extract all of these patches from im
as sub-arrays without looping through. My current looping solution is something like:
for x, y, w, h in windows:
patch = im[y:(y+h),x:(x+w)]
But I'd like a nice array-based operation to get all of them, if possible.
Thanks.