bg_removal script usage example?

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
phraktle
Posts: 2
Joined: 2017-11-01T03:25:04-07:00
Authentication code: 1151

bg_removal script usage example?

Post by phraktle »

Hi,

I'm trying to use the bg_removal script on an image with a white background, for example this one: http://goo.gl/PQAnLs

The following simple floodfill method yields the expected transparency:

Code: Select all

convert foo.jpg -bordercolor white -border 1x1 -alpha set -channel RGBA -fuzz 3% -fill none -floodfill +0+0 white -shave 1x1  -format png foo.png
However, with bg_removal I don't seem to get any transparency. I've tried various parameters with no luck, for example:

Code: Select all

bg_removal foo.jpg white 10 10 foo.png
Any hints / examples on how to use the bg_removal script properly?

(my ImageMagick version is 7.0.7-8 Q16 x86_64 2017-10-24)

Thanks,
Viktor
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bg_removal script usage example?

Post by fmw42 »

What is your platform? What is your version of libpng? (mine is 1.6.29_0)

It works fine for me using IM 7.0.7.8 Q16 Mac OSX. However, there is still shadow showing that has not been turned to white. So you may need to increase the fuzz value.

Code: Select all

magick foo.jpg -bordercolor white -border 1x1 -alpha set -channel RGBA -fuzz 3% -fill none -floodfill +0+0 white -shave 1x1  foo.png
Note I removed -format png, since the output has a png suffix. But it works even with -format png.

If that does not help, try using -draw to do the flood fill

Code: Select all

magick foo.jpg -bordercolor white -border 1x1 -alpha set -channel RGBA -fuzz 3% -fill none -draw "alpha 0,0 floodfill" -shave 1x1  foo.png
phraktle
Posts: 2
Joined: 2017-11-01T03:25:04-07:00
Authentication code: 1151

Re: bg_removal script usage example?

Post by phraktle »

The first command works for me as well, it is the bg_removal script I'm having no luck with...

My platform is MacOSX as well.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bg_removal script usage example?

Post by fmw42 »

That script was written by Anthony Thyssen on 3 July 2009. So it is likely using very old IM 6 syntax and probably does not work on IM 7. Its code would have to be made compatible with IM 7.

See http://www.imagemagick.org/Usage/masking/#semi-trans, which is where that script is referenced to replace the code example. Perhaps try the commands in that section.
Post Reply