Page 1 of 1
Make transparent only large areas
Posted: 2011-12-28T09:40:27-07:00
by ghostm
Hi, is there any solution, allowing to convert only large areas of white color? I used -floodfill, maybe it would solve my problem, but I don't know how to use imagemagick to detect areas of white bigger than for example 5x5pixels. I have thousands of images containing multiple white areas, but simple use of -transparent option, even with -fuzz, leaves several ugly 1 pixel transparent points. Thanks in advance!
Re: Make transparent only large areas
Posted: 2011-12-28T12:08:49-07:00
by fmw42
I am not quite sure what you are changing white to. So the following may or may not work without modification.
Use your floodfill or -fuzz as before so that you keep the white areas and the rest is make black so as to create a mask. Negate the mask. Then use -morphology open to remove white pixels in the mask that are small as defined by the kernel size and shape. Once you have cleaned up your mask, negate it and add it into the alpha channel of the image to make the black regions in the mask as transparent in your image.
Here is one example using the IM internal image logo:
convert logo: \
\( -clone 0 -fill black +opaque white -negate -morphology open disk:2 \) \
-alpha off -compose copy_opacity -composite logo_trans.png
It might be good idea to explain further and post a link to your image or some sample image that you want to test with and someone can likely create a full example of the processing. Also identify your IM version and platform.
The above example is unix syntax. If on Windows, see
http://www.imagemagick.org/Usage/windows/ for syntax differences
Re: Make transparent only large areas
Posted: 2011-12-29T04:28:44-07:00
by ghostm
I'm changing white backgound color into 100% transparent. Your tip works better than my previous attempts, there are two of my testing images, but it still needs some improvements, especially with necklace:
http://allani.pl/system/images/000/044/ ... 1315673828
http://allani.pl/system/images/000/039/ ... 1313491434
ImageMagick 6.6.2-6, Ubuntu 11.04