identify+remove background

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
sdf
Posts: 1
Joined: 2011-10-21T00:06:17-07:00
Authentication code: 8675308

identify+remove background

Post by sdf »

I tried to write a command line to remove the background of this old phototype.

I tried to identify the background and convert it to transparent. Though none of the command-line scripts worked. The image remained the same as in the input-image. I tried to get my way through these scripts:

Code: Select all

convert input_image.jpg -bordercolor black -border 1x1 -alpha set -channel RGBA -fuzz 20% -fill none -floodfill +0+0 white -shave 1x1 output_image
Worked my way through these turorials:
http://www.imagemagick.org/Usage/color_basics/#replace
http://www.imagemagick.org/Usage/color_basics/#opaque
http://www.imagemagick.org/Usage/masking/#bg_remove
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: identify+remove background

Post by anthony »

flood fill will not do anything unless the 'seed' point is also within the 'fuzz' distance of the color you are searching for (white). as you added a black border that seed pixel is black, so floodfill does nothing (seed fails to match).

See Floodfill operator
http://www.imagemagick.org/Usage/color_ ... #floodfill

I would recommend the more complex method of attempting to extract the semi-transparent 'anti-aliasing' pixels from the resulting image.

Ideally you would need to know the original background of the image to do this. but in this case your background is not very uniform. Their is however solutions for recovering the background, at least around the edges of the foreground object, to let you use those more complex methods.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply