Replace ANY colour Except #ffffff with #000000
Replace ANY colour Except #ffffff with #000000
So I have this picture:
And want to repace all colours EXCEPT #ffffff with #A7A7AF
I hope this can be done "pixle perfect".
Thanks in advance.
And want to repace all colours EXCEPT #ffffff with #A7A7AF
I hope this can be done "pixle perfect".
Thanks in advance.
Last edited by Rye on 2014-06-20T12:14:33-07:00, edited 2 times in total.
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replace ANY colour Except #ffffff with #000000
Unfortunately, your image has no pure white #ffffff
If it did, then
If you want to use a fuzz value to catch the close to white values then try
Adjust the fuzz value as desired
If it did, then
Code: Select all
convert "Snow_Sharo 001.gif" -fill "#A7A7AF" +opaque "#ffffff" result.gif
Code: Select all
convert "Snow_Sharo 001.gif" -fuzz 5% -fill "#A7A7AF" +opaque "#ffffff" result.gif
Re: Replace ANY colour Except #ffffff with #000000
the second command seems to do nothing to my picture (I replaced "show:" with result.gif).
Am I doing something wrong ?
I also played around with the fuzz value as instructed, however the change was still - nothing...
This command *did* something, however still not as good as I wished it to be:
Am I doing something wrong ?
I also played around with the fuzz value as instructed, however the change was still - nothing...
This command *did* something, however still not as good as I wished it to be:
Code: Select all
convert "001.gif" -fill white +opaque #A7A7AF -transparent white result.gif
Last edited by Rye on 2014-06-20T12:10:22-07:00, edited 1 time in total.
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replace ANY colour Except #ffffff with #000000
Sorry, I forgot to replace show: with a filename. Edited now to fix that.
If you are on Windows replace % with %%.
Note the double quotes about your file name, since it has spaces in it. I am not sure how Windows handles that.
see http://www.imagemagick.org/Usage/windows/
Note again, that the image you provide has not perfectly white pixels.
If you are on Windows replace % with %%.
Code: Select all
convert "Snow_Sharo 001.gif" -fuzz 5%% -fill "#A7A7AF" +opaque "#ffffff" result.gif
Note the double quotes about your file name, since it has spaces in it. I am not sure how Windows handles that.
see http://www.imagemagick.org/Usage/windows/
Note again, that the image you provide has not perfectly white pixels.
Re: Replace ANY colour Except #ffffff with #000000
using a second % doesn't help.
How can I find the version etc. ?
How can I find the version etc. ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replace ANY colour Except #ffffff with #000000
Post your exact command and the input image.
To get the IM version,
To get the IM version,
Code: Select all
convert -version
Re: Replace ANY colour Except #ffffff with #000000
Code: Select all
convert 001.gif -fuzz 5%% -fill "#A7A7AF" +opaque "#ffffff" 002.gif
IMGMagick version:
Version: ImageMagick 6.8.3-4 2013-02-20 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replace ANY colour Except #ffffff with #000000
It has converted your background from #A8A8B0 to #A7A7AF. But there is little (visual) difference in that color change.Rye wrote:This does nothing to the image posted above (have you found a satisfactionary code that works with the above image ?)Code: Select all
convert 001.gif -fuzz 5%% -fill "#A7A7AF" +opaque "#ffffff" 002.gif
try
Code: Select all
convert 001.gif -fuzz 5%% -fill "#FF0000" +opaque "#ffffff" 002.gif
Re: Replace ANY colour Except #ffffff with #000000
Is it possible to define multiple colors that are to be exluded from the replace ?
If I would like to replace any colour except for these three: #F4F4FC #F7F7FF #F9F9FF with let's say #000000.
How'd I do it ?
If I would like to replace any colour except for these three: #F4F4FC #F7F7FF #F9F9FF with let's say #000000.
How'd I do it ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replace ANY colour Except #ffffff with #000000
As long as your image has no (partial or fully) transparent pixels, then do the following
Unix:
Windows:
Add -fuzz if so desired to get close colors.
Unix:
Code: Select all
convert yourimage \
-fill none -opaque "#F4F4FC" \
-fill none -opaque "#F7F7FF" \
-fill none -opaque "#F9F9FF" \
\( -clone 0 -fill "#000000" -colorize 100 \) \
+swap -compose over -composite resultimage
Windows:
Code: Select all
convert yourimage ^
-fill none -opaque "#F4F4FC" ^
-fill none -opaque "#F7F7FF" ^
-fill none -opaque "#F9F9FF" ^
( -clone 0 -fill "#000000" -colorize 100 ) ^
+swap -compose over -composite resultimage
Re: Replace ANY colour Except #ffffff with #000000
This outputs:
"convert.exe: invalid argument for option '-colorize': #000000 @ error/convert.c/ConvertImageCommand/969."
"convert.exe: invalid argument for option '-colorize': #000000 @ error/convert.c/ConvertImageCommand/969."
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Replace ANY colour Except #ffffff with #000000
I think Fred made a typo and meant "-colorize 100" (no quotes needed).
The following Windows BAT script makes a sample file. From this, it makes all colours except the specified colours into purple. Change "purple" to anything you want.
There may be a simpler method.
The final "-unique-colors" is to verify the result.
The following Windows BAT script makes a sample file. From this, it makes all colours except the specified colours into purple. Change "purple" to anything you want.
There may be a simpler method.
Code: Select all
convert ^
-size 20x20 ^
xc:red xc:lime xc:blue xc:#F4F4FC xc:#F7F7FF xc:#F9F9FF xc:khaki ^
+append ^
sample.png
convert ^
sample.png ^
( -clone 0 -fill Purple -colorize 100 ) ^
+swap ^
-alpha set ^
( -clone 1 ^
( -clone 0 +transparent #F4F4FC ) ^
( -clone 0 +transparent #F7F7FF ) ^
( -clone 0 +transparent #F9F9FF ) ^
-delete 0 ^
-evaluate set 0 ^
-layers flatten ^
-negate ^
) ^
-compose Over -composite ^
s1.png
convert ^
s1.png -unique-colors txt:
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replace ANY colour Except #ffffff with #000000
Yes, indeed I made a mistake. Thanks for catching it snibgo. I have fixed my command above.I think Fred made a typo and meant "-colorize 100" (no quotes needed).
Re: Replace ANY colour Except #ffffff with #000000
Ok, perfect, now it works
BTW: colorize seems to only "tone" the color down.
Is there a way to make it pitch black (for example) just by once executing this ?
BTW: colorize seems to only "tone" the color down.
Is there a way to make it pitch black (for example) just by once executing this ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replace ANY colour Except #ffffff with #000000
use
The 100 means totally change to that exact color. Alternately, you can use
In place of the above. That will make any image totally black. There are lots of ways to do this.
see
http://www.imagemagick.org/Usage/canvas/#solid
and especially
http://www.imagemagick.org/Usage/canvas/#other
Code: Select all
-fill black -colorize 100
Code: Select all
-evaluate set 0
see
http://www.imagemagick.org/Usage/canvas/#solid
and especially
http://www.imagemagick.org/Usage/canvas/#other