Page 1 of 1

From white to transparent (Solved)

Posted: 2010-01-22T06:57:52-07:00
by Albireo
Hello!

The image has a white background (color?), and I would like to replace the white color with transparent color.
(I think it is white :) )

Is it possible with ImageMagick?

//Jan

Re: From white to transparent

Posted: 2010-01-22T10:49:23-07:00
by fmw42
convert image -fuzz XX% -transparent white result

XX is tolerance to match white, try 5% or so

see

http://www.imagemagick.org/script/comma ... ransparent
http://www.imagemagick.org/script/comma ... s.php#fuzz

Re: From white to transparent

Posted: 2010-01-22T14:45:21-07:00
by Albireo
fmw42 wrote:convert image -fuzz XX% -transparent white result
XX is tolerance to match white, try 5% ......
Thank you!

It works! :)

With 5% became the image rather "frayed".
With 20% were the border line good.
(however it began to emerge "weaker" color in the middle of the picture :-)


//Jan

Re: From white to transparent (Solved)

Posted: 2010-01-22T18:09:44-07:00
by fmw42
If the image is white at 0,0 (or any other pixel you want to identify), then try

convert image -fill none -fuzz 20% -draw 'matte 0,0 floodfill' result.png

This will floodfill the outside with transparency and not touch inside areas that are near white.

Again adjust the fuzz value as desired.

Re: From white to transparent (Solved)

Posted: 2010-01-22T22:59:50-07:00
by Albireo
fmw42 wrote:If the image is white at 0,0 (or any other pixel you want to identify), then try
convert image -fill none -fuzz 20% -draw 'matte 0,0 floodfill' result.png
This will floodfill the outside with transparency and not touch inside areas that are near white.
Again adjust the fuzz value as desired.
Good idea!
The result was better in one way the edges is much better, but

The white area between some characters in bottom are left white
and the white in the middle of the logo is also provided white....

//Jan

Re: From white to transparent (Solved)

Posted: 2010-05-25T23:40:00-07:00
by anthony
See IM Examples of Color replacement
http://www.imagemagick.org/Usage/color/#replace

However direct color replacement like this causes aliasing effects around the image edges.
So it really depends on what you are doing as to if this is suitable.

The alternative is to try to feather the image edge, (uses in photos)
See raw feathering notes from morphology (this link will change)
http://www.imagemagick.org/Usage/morpho ... ce_feather
And this on Blur Feathering or False Feathering Technique
http://www.imagemagick.org/Usage/blur/#feathering

Or you can try to work out what color and transparency edge pixels should have (used in objects with a definite border)
See Background Masking
http://www.imagemagick.org/Usage/channe ... k_creation

All these different sections really needs to be collected merged together into a new practical example section, so that it is all in one place, and which looks at the advantages and disadvantages of the various methods with different images.

As it is I have enough to do just writing up the new Image Morphology and Convolution additions.

Hmmm I'll just get of my soap box now :lol: