in reply to Subimage replacement script

When I was trying to OCR screenshots a few years ago, I collected a directory full of snippets of the possible characters, and then wrote a helper script to find which pixels to sample to eliminate the most possibilities at each step and save the results into a HoHoHo...H search tree/dictionary (each leaf node being the character found, and other nodes containing pixel coordinates to check and a pair of hashrefs to follow depending on the pixel color).

That way the characters could be determined from 5-10 samples instead of a full comparison, and variable width characters were supported. Sampling a pixel further right than a potential character's size could not eliminate it as a possibility; the tree would eventually prefer a pixel that could eliminate the narrower characters.

All my images were downsampled to 1-bit per pixel to keep it simple, and the start position was known relative to the window coordinates, so that helped a bunch.

Perhaps you could try doing a search for a known character and then scan outwards from that? Something vaguely like /01110.{$img_width_minus5}10001.{$img_width_minus5}10001.{$img_width_minus5}01110/ to search for an 'o' shape anywhere in the image. Once you've found one character, then you've found the grid.