I am writing some code, whereby I store a greyscale image, which is split into 'blocks' in a 4D array. I will be looping through all the 'blocks' in the 4D array and will perform calculations based on the contents of the blocks compared to one another. I want to only compare the 'blocks' that are near each other, and to do this I can just calculate the distance between the 'blocks' and don't loop through the ones that are too far away. To do this I need the index of each 'block' in the 4D matrix, ultimately creating my question.
My code goes like this:
for i=4dmatrix1
for j=4dmatrix2
% Do calculations here involving the index of i
% and j in their respective matrices.
end
end
I have i and j, but I want to find their index in 4dmatrix1 and 4d matrix2 respectively. 4dmatrix1 and 4dmatrix2 are greyscaled images that have been split into "blocks" of 20x20 pixels. Each matrix in 4dmatrix1 and 4dmatrix2 is a "block" in image 1 and image 2. The reason I have used this method for storing the data as it still represents the shape of the image, just split into 20x20 blocks. In my head this is understandable, but maybe for programming, this is inefficient and should be changed. If so, what would you recommend looking into?
Thank you!