I have the an image represented in nd-array. Let's assume that the shape of it is (256, 256, 3)
.
I wish to slice the image to sub arrays each of size (128, 128, 3)
with a stride of 64.
I did the following to get the desired indices:
for x1, x2 in (zip(range(0, 257, 64), range(128, 257, 64))):
for y1, y2 in (zip(range(0, 257, 64), range(128, 257, 64))):
print("rows:",x1,x2,", columns:",y1,y2)
I get the following indices to slice:
rows: 0 128 , columns: 0 128
rows: 0 128 , columns: 64 192
rows: 0 128 , columns: 128 256
rows: 64 192 , columns: 0 128
rows: 64 192 , columns: 64 192
rows: 64 192 , columns: 128 256
rows: 128 256 , columns: 0 128
rows: 128 256 , columns: 64 192
rows: 128 256 , columns: 128 256
Now I can slice each sub array and stack it, moreover, I will want to stack the slices again after some operations on each sub-array and averaging the values.
I was wondering if there is a smarter way of doing it to be able to use it for multiple strides/image sizes.