How can I change all pixels of one color to another color in a picture?

I have an image which looks like this:

Enter image description here

However, the yellow line needs to be red and the cyan line needs to be green. I have Paint and IrfanView. How can I change the colors of the yellow and cyan line without individually selecting all pixels manually?

That is, what is a good way of changing all pixels of one color to another color?


Solution 1:

Paint.NET will do it, You just need to do a fill, with 'global' mode instead of contiguous mode.

As per request. I'd note the original was horribly noisy and I cleaned it up a bit. You'd ideally want to clean this up first

enter image description here

There's a few important things here.

Firstly, I was zoomed into the image so I could pick the correct area more easily. There was a ton of anti-aliasing here so I ended up sharpening it (or otherwise cleaning it up), but even then, I went with a fairly high tolerance (The higher the tolerance, the less similar an adjoining pixel needs to be to its neighbours to be recoloured) Play with that value - lower is more 'precise' but you may need a higher value.

Solution 2:

ImageMagick can do all sorts of fancy color replacements.