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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
rshea
Posts: 11
Joined: 2009-11-30T02:06:33-07:00
Authentication code: 8675309

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

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
rshea
Posts: 11
Joined: 2009-11-30T02:06:33-07:00
Authentication code: 8675309

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

Post by rshea »

Thanks to you both. I ended us using the fmw42 option but thank you snigbo for your suggestion, much appreciated.

regards

Richard.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

fmw's suggestion is better than mine: more elegant and probably faster.
snibgo's IM pages: im.snibgo.com
Post Reply