Change a single range and the rest black

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
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Change a single range and the rest black

Post by gaylorr »

I am trying to take an image, make ALL of it black, except for a specific color range (of DarkOliveGreen) but not having luck

The image has alpha (PNG alpha, not an actual Alpha channel), which I want to also make go away.

convert imageIn.png -fuzz 7.5% -fill white -opaque DarkOliveGreen PNG24:imageOut.png

How do I select everything EXCEPT the above color range and make it black?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change a single range and the rest black

Post by fmw42 »

Code: Select all

convert imageIn.png -alpha off -fuzz 7.5% -fill white -opaque DarkOliveGreen \
-fuzz 0 -fill black +opaque white PNG24:imageOut.png
see
http://www.imagemagick.org/script/comma ... php#opaque

"Use +opaque to paint any pixel that does not match the target color."

P.S. Please always provide your IM version and platform when asking questions. See viewtopic.php?f=1&t=9620
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Change a single range and the rest black

Post by gaylorr »

Thank you very much!
fmw42 wrote:P.S. Please always provide your IM version and platform when asking questions. See viewtopic.php?f=1&t=9620
Absolutely...sorry about that.... 6.9.2-4 Q8 x64 windows 7 Pro
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change a single range and the rest black

Post by fmw42 »

You do not say what your platform is. IM syntax differs on Windows and Unix
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Change a single range and the rest black

Post by gaylorr »

fmw42 wrote:

Code: Select all

convert imageIn.png -alpha off -fuzz 7.5% -fill white -opaque DarkOliveGreen \
-fuzz 0 -fill black +opaque white PNG24:imageOut.png
That yields an entirely black image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change a single range and the rest black

Post by fmw42 »

Are you on Windows or Unix? If Windows, then try

Code: Select all

convert imageIn.png -alpha off -fuzz 7.5% -fill white -opaque DarkOliveGreen ^
-fuzz 0 -fill black +opaque white PNG24:imageOut.png
Otherwise, please post your image to some place such as dropbox.com and put the URL here, so we can test with it.
gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Change a single range and the rest black

Post by gaylorr »

It is Windows...(I had previously edited my post to include that) and I am using command line batch (cmd) files...(yes I remembered to use %% this time ;-) )

Thanks! I am still getting the hang of all that this amazing program can do, but more importantly, HOW to get there...
fmw42 wrote:Are you on Windows or Unix? If Windows, then try

Code: Select all

convert imageIn.png -alpha off -fuzz 7.5% -fill white -opaque DarkOliveGreen ^
-fuzz 0 -fill black +opaque white PNG24:imageOut.png
Otherwise, please post your image to some place such as dropbox.com and put the URL here, so we can test with it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change a single range and the rest black

Post by fmw42 »

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change a single range and the rest black

Post by fmw42 »

gaylorr
Posts: 31
Joined: 2015-10-15T11:02:44-07:00
Authentication code: 1151

Re: Change a single range and the rest black

Post by gaylorr »

In the end, this worked:

convert ImageIn.png -alpha remove -fuzz 7.5%% -fill black +opaque DarkOliveGreen -fill white -opaque DarkOliveGreen PNG24:ImageOut.png

So that very much helped me figure it out...thanks!

This gives me an entirely black image except where I had green, and then turns that to white....perfect!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change a single range and the rest black

Post by fmw42 »

That is why one needs to provide the platform you use each time, so that we can provide the correct syntax. Also in bat files you do need to double the % to %%. For normal terminal commands and bat files, you need to use ^ for new line markers and and when using percents do not escape with \. See http://www.imagemagick.org/Usage/windows/
Post Reply