From white to transparent (Solved)

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
Albireo
Posts: 68
Joined: 2010-01-12T03:32:23-07:00
Authentication code: 8675309

From white to transparent (Solved)

Post 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
Last edited by Albireo on 2010-01-22T14:45:46-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: From white to transparent

Post 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
Albireo
Posts: 68
Joined: 2010-01-12T03:32:23-07:00
Authentication code: 8675309

Re: From white to transparent

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: From white to transparent (Solved)

Post 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.
Albireo
Posts: 68
Joined: 2010-01-12T03:32:23-07:00
Authentication code: 8675309

Re: From white to transparent (Solved)

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: From white to transparent (Solved)

Post 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:
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply