Make Simple Background Transparent

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
Larsenv
Posts: 10
Joined: 2016-05-15T08:49:00-07:00
Authentication code: 1151

Make Simple Background Transparent

Post by Larsenv »

Using a Mac with ImageMagick 6.9.1-10, how can I remove this background and make it transparent?

Image

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

Re: Make Simple Background Transparent

Post by fmw42 »

What is background? Is it just the color outside the darker brown region or is it everything but the sofa/chair? Either way, it will be very hard, since the chair color is similare to the rest of the image. If you have a picture that is the same but without the chair, then you can try subtracting that from the image. Otherwise, you will have to manually draw a black/white mask and use that to make the background transparent using

Code: Select all

convert Modwoosof.jpeg mask -alpha off -compose copy_opacity -composite result.png
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Make Simple Background Transparent

Post by Bonzo »

If it is the area outside the brown region could you add a border the same colour, floodfill ( can you floofill transparent? ) and then crop or shave back to the original?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Make Simple Background Transparent

Post by snibgo »

The answer is easy: do it in Gimp.

I'm serious. IM is not the right tool for this job.

But perhaps there is something the OP hasn't said. Perhaps there are 1000 images, all with the same background, which is to be removed. Or something.
snibgo's IM pages: im.snibgo.com
Larsenv
Posts: 10
Joined: 2016-05-15T08:49:00-07:00
Authentication code: 1151

Re: Make Simple Background Transparent

Post by Larsenv »

snibgo wrote:But perhaps there is something the OP hasn't said. Perhaps there are 1000 images, all with the same background, which is to be removed. Or something.
No joke, there are thousands of these.

The problem is that making them transparent in Photoshop or GIMP for these would be very tedious

The background's the orange thing.

Image

Is there a way to make that actually go away or not?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Make Simple Background Transparent

Post by fmw42 »

If the brown "ring" goes all the way round inside the image boundary, then you can do what bonzo suggested. Add the same background color to a border of at least one pixel wide, then make that color transparent.

Assuming that the upper left corner pixel is always your background color, then this works.

Code: Select all

bgcolor=`convert 8m3q3jS.jpg -format "%[pixel:u.p{0,0}]" info:`
convert 8m3q3jS.jpg -bordercolor $bgcolor -border 1 \
-fuzz 10% -fill none -draw "matte 0,0 floodfill" -shave 1x1 8m3q3jS_trans.png
Image

The -fuzz 10% is needed, since you have a jpg input and the jpg compression makes the background not a constant color, but slightly off in blocks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Make Simple Background Transparent

Post by snibgo »

These two images seem to have the same background. Are they the same size? Then find a set of images such that at every pixel is the background on at least one image. Then you can make an image that is entirely background. Then, for every image, were a pixel isn't background, it's a foreground pixel.

I hope your files aren't jpeg. If they are, you'll need fuzz and probably noise-reduction.
snibgo's IM pages: im.snibgo.com
Post Reply