Here's a solution that works exceptionally well. Average the three colors. Assign the average to all but the highest valued color. This doesn't account for colors having the same value, but this demonstrates a temporary solution to that case.
Code:
// sample the center of the image //
COLORREF pixel = buff.Pixel(width/2, height/2);
int r = Red(pixel);
int g = Green(pixel);
int b = Blue(pixel);
int average = (r+b+g)/3;
if(r > g && r > b) g = b = average;
else if(g > r && g > b) r = b = average;
else if(b > r && b > g) r = g = average;
else
{ // temporary solution to gray images //
r = g = b = average >= 127 ? average - 64 : average + 64;
}
bool ip = IsPalette(pixel);
COLORREF replace = ip ? PALETTERGB(r,g,b) : RGB(r,g,b);
for(int i = 0; i < width; ++i)
for(int j = 0; j < height; ++j)
if(buff.Pixel(i, j) == pixel)
buff.Pixel(i, j, replace);