Page 1 of 1

Change all pixels of colour 'a' to colour 'b'

Posted: 2010-03-21T15:23:46-07:00
by rshea
I'm sure this is the simplest question asked in a long time but I can't see how to do it.

I have an image in which all pixels which are currently, say, RGB(10,10,10) I want changed to RGB(20,20,20).

I've looked at -clut but that seems very complex for the problem involved.

To be specific the histogram of the image I have looks like this :

Code: Select all

  Histogram:
   1489484: #00000000 black
     42810: #000000FF black
     37306: #7E3B0E00 cmyk(126,59,14,0)
... and I want to change all those cmyk(126,59,14,0) to cmyk(76, 25, 12, 51) (or equivalently cmyk(30% ,10% ,5% ,20%)).

I'm sure there's an easy way to do this but I can't find it !

Would be grateful for any help.

Re: Change all pixels of colour 'a' to colour 'b'

Posted: 2010-03-21T16:27:20-07:00
by snibgo
I don't know the fastest or most elegant way, but this will work:

convert in.png -alpha on -transparent rgb(10,10,10) -background rgb(20,20,20) -flatten out.png

For the rgb expressions, substitute what you want.

Re: Change all pixels of colour 'a' to colour 'b'

Posted: 2010-03-21T17:01:42-07:00
by fmw42
if you are on a reasonably current IM version

convert image.jpg -fill "cmyk(76,25,12,51)" -opaque "cmyk(126,59,14,0)" result.jpg

note the quotes are important

see

http://www.imagemagick.org/script/color.php

see also my unix bash script, mapcolors, below

Re: Change all pixels of colour 'a' to colour 'b'

Posted: 2010-03-21T17:20:24-07:00
by rshea
Thanks to you both. I ended us using the fmw42 option but thank you snigbo for your suggestion, much appreciated.

regards

Richard.

Re: Change all pixels of colour 'a' to colour 'b'

Posted: 2010-03-22T02:12:21-07:00
by snibgo
fmw's suggestion is better than mine: more elegant and probably faster.