I want to construct an algorithm in Python to slice an image into n-by-n equal blocks. I am aware of existing Python packages that can do this, but I am interested in performing mathematical computations using the dimensions of the resulting blocks, which need not be integer values.
I have successfully converted my image input into ndarray using numpy and cv2. I am curious if I can slice an ndarray object in a way so that when I split a "pixel", I simply take the weighted average of that "pixel's" contribution to their respective block.
For example, if the image input have dimensions 100px x 100px, and I want to split this image into 7x7 blocks, since 100/7 = ~14.2857, each block will have dimensions 14.2857 x 14.2857. But it doesn't make sense to have a fraction of a pixel. Instead, I wish to interpret this so that the first block contains all of the information from pixels (1,1),(1,2),...,(1,14),(2,1),...,(3,1),...,(14,1),... ,(14,14), 0.2857 of all pixels satisfying (15,k) and (k,15), and 0.2857*0.2857 for pixel (15,15). I wish to do this for all 49 blocks.
Any insight would be appreciated! Thanks.