I think you want an algorithm like the following:
- Compute the mean RGB value for a given subimg.
- Compute the Euclidean distance from your mean RGB value to the RGB value in each of the squares.
- Return the square name that is closest to your RGB value.