Overlaying a line-grid on top of an image is a very common operation. Image A is a 8x8 image expanded by a factor of 20 using pixel replication. The grid is built using the negation of the maximum of a vertical grid and a horizontal grid:
--
--
Left: Zoomed Image
Center: Vertical Grid
Right: Horizontal Grid
--
--
Left: White Grid: Maximum between Vertical and Horizontal Grids
Center: Black Grid: 255 - White Grid (Negation)
Right: Minimum between Zoomed Image and Black Grid
--
--
Left: Original
Center: Overlay
Right: Maximum between Original and Overlay