You'll probably have to use something like OpenCV.
Generate a histogram of the image to find the most common color.
Find contours and limit it to contours with 4 sides (i.e. rectangles)
Color in the contour with the calculated color.
However an easier approach, instead of coloring in the rect might be to, again using OpenCV:
Find 4 sided contours
Perspective correct the internals of the contour so that the text is de-skewed
Process this region of the image