Page 1 of 1

Change a single range and the rest black

Posted: 2015-11-17T12:22:30-07:00
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?

Re: Change a single range and the rest black

Posted: 2015-11-17T12:39:04-07:00
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

Re: Change a single range and the rest black

Posted: 2015-11-17T12:52:34-07:00
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

Re: Change a single range and the rest black

Posted: 2015-11-17T12:53:28-07:00
by fmw42
You do not say what your platform is. IM syntax differs on Windows and Unix

Re: Change a single range and the rest black

Posted: 2015-11-17T12:59:29-07:00
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.

Re: Change a single range and the rest black

Posted: 2015-11-17T13:07:23-07:00
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.

Re: Change a single range and the rest black

Posted: 2015-11-17T13:14:43-07:00
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.

Re: Change a single range and the rest black

Posted: 2015-11-17T13:17:16-07:00
by fmw42

Re: Change a single range and the rest black

Posted: 2015-11-17T13:22:34-07:00
by fmw42

Re: Change a single range and the rest black

Posted: 2015-11-17T13:28:09-07:00
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!

Re: Change a single range and the rest black

Posted: 2015-11-17T13:32:31-07:00
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/