I would recommend to not focus on the performance and backend at the beginning as your use case is not trivial.
Would the grid be used in fixed windows or would the window size also be changed depending on the image location?
In the first step, I would recommend to use either a nested loop and make sure your method is working as expected and then use unfold to create the windows and calculate the output via a matrix multiplication, if that fits your use case.