# ColorReplace does not work

I want to do - seemingly - simply image processing. I want to replace all blue pixels with white pixels. The obvious command would be:

ColorReplace[image2, Blue -> White]

Instead of getting the desired result, i.e. the picture, in which the blue line is changed to white, I get the following:

ColorReplace[image2, RGBColor[0, 0, 1] -> GrayLevel[1]]


Any ideas?

Do you see an error message in the Messages window? When this happens (the result of an evaluation is more or less the expression you entered), it's usually because it can't be evaluated, e.g. because image2 is not actually an image. If I Import the image from your post, ColorReplace accepts it as an argument, but since the blue you're trying to replace isn't exactly Blue, it doesn't replace anything.

You can use a trick from the ColorReplace documentation, and look for the closest "bluish" color that's actually in the image, and replace that:

image2 = Import["http://i.stack.imgur.com/lGVPj.png"];

g = Nearest[DominantColors[image2, 10], Blue,
DistanceFunction -> ColorDistance]
ColorReplace[image2, g[[1]] -> White]


,

This mostly works, except that I guess anti aliasing makes parts of the blue line darker than ColorReplace's threshold. You can play with the threshold (that last parameter), but I think if you only want to make blue pixels white, the easiest way would be to just use the blue channel:

ColorSeparate[image2][[3]]


• I don't see an error message when I execute the command. I thought that the option "Blue->White" in the ColorReplace command already takes all "blueish" colors. I also tried the ColorReplace by exactly stating the blue color: ColorReplace[image2,RGBColor[0.0196,0.5725,0.8314]->RGBColor[1,1,1]], but that also didn't work. Anyway: Thanks a lot! – Niki Jul 31 '15 at 8:04