First it is not just 'white' you want to preserve, but all the white-red border colors (anti-alising). As such you need to be careful.
In my images I sort of cheated and used "love_gnome_bw.png" which had already been cleaned. I simply overalys that image on 'black' and presto just the center white part was kept. Already a mask. The heart as you know was just a alpha extract.
Rememin you want to preserve the edge, so you don't want to modify those pixels (except when you do global modification of all pixels).
Their are basically two methods of getting a area of color while preserving the 'thin' anti-aliasing edge.
One is just load it in an image editor and manuall make all the non-white colors (transparency in this case) the same 'red' as everthing else. A greyscale and -auto-level should then convert it to a mask, while preserving the anti-alias.
The second assumes each color is cleaning surrounded by another color (red). We get a mask, 'dilate it' and then use it to wipe out everything else.
Hmmm
Code: Select all
convert logo.png +transparent white \
-channel A -morphology dilate square:2 +channel \
-background '#c71807' -alpha remove \
-type grayscale -auto-level \
love_gnome_foot.png
first line wipes all non -pure white colors. -- this is VERY aliased.
second dilate the alpha. channel enough to cover all anti-aliasing pixels.
Flatten that onto the surrounding color '#c71807' - yes this step is horrible - a better method needed
and turn result into a mask. -- complete with anti-aliasing.
DAMN -- this image is so unclean the auto-level still fails to make the surrounding background pure black! Seems their are some ringing effects in the anti-aliasing pixels around the foot. Either from 'sharpening' or from having been saved using JPEG at some point in its past. This image is ok buit you may need to watch for 'negative ringing' inside the shape as well as outside.
See Ringing Artifacts
http://www.imagemagick.org/Usage/resize/#ringing
You will need to use -normalization or -contrast-stretch to fix this,
http://www.imagemagick.org/Usage/color_mods/#normalize
though it will modify anti-aliasing slightly.
OR better still extract the new 'not quite black' result and use -level-colors
Code: Select all
convert logo.png +transparent white \
-channel A -morphology dilate square:2 +channel \
-background '#c71807' -alpha remove \
-type grayscale -auto-level \
-level-colors '#0b0e0b0e0b0e',white \
love_gnome_foot.png
NOTE in IMv7 IM will be able to directly extract that horible '#0b0e0b0e0b0e' color -- IMv6 can not!
Note we probably could probably have merged -auto-level and -level-colors together. They essentually do similar operations onto the image