I tried to provide a diagram for my situation. Essentialy I have a 1280 X 1024 pixel image that needs to be processed through an equation that specifically requires each individual pixel to be put through a function in a 9x9 square, ignoring the edge cases where a 9x9 square cannot be formed. I've created a nested for loop that goes through each individual pixel in the image, but don't know how to select a 9x9 matrix to work with. Based on the diagram below, the target pixel iterates from the black, to purple, to blue, then to pink box.
As the function processes each individual pixel, I do not want it to modify the original image, rather store it in a new image. For context, this is for producing a laser speckle contrast image.
I've also tried using mat2tiles, but that doesn't meet the criteria for the problem i'm trying to solve since it creates a tile, rather than average the next pixel in the image.