If you want to know why there's the need for the pointers.... Read below:
The need for the pointer because, you would not need to traverse NxM(width x height), but instead, you probably just need to traverse window_min to window_max.
But initially, you need to set the ptrs of each pixel to the gray_scale arrays.
Email me, if you want more details. Or leave comments.