Extract Transparent Foreground From Image

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
coolperez8
Posts: 27
Joined: 2016-03-11T07:27:11-07:00
Authentication code: 1151

Extract Transparent Foreground From Image

Post by coolperez8 »

So, I have an original image and a modified version of the same image with a transparent foreground. Both images (including the foreground in the modified image) seem to have transparency. What I want to do is remove the original image portion from the modified image so I get the transparent foreground by itself with no traces of the original image. What command should I use to achieve this?

ImageMagick Version: ImageMagick 6.9.3-4 Q16 x64 2016-02-13 (Running on Windows 10)
Last edited by coolperez8 on 2016-04-04T15:41:20-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extract Transparent Foreground From Image

Post by snibgo »

I don't understand. If you remove the original image apart from the transparent foreground, what are you left with? Example images might help.

Please also read the IMPORTANT: Please Read This FIRST Before Posting thread.
snibgo's IM pages: im.snibgo.com
coolperez8
Posts: 27
Joined: 2016-03-11T07:27:11-07:00
Authentication code: 1151

Re: Extract Transparent Foreground From Image

Post by coolperez8 »

snibgo wrote:I don't understand. If you remove the original image apart from the transparent foreground, what are you left with? Example images might help.

Please also read the IMPORTANT: Please Read This FIRST Before Posting thread.
Basically, you remove the original image from the modified image and you're left with the transparent foreground.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extract Transparent Foreground From Image

Post by snibgo »

How about:

Code: Select all

convert in.png -alpha transparent out.png
snibgo's IM pages: im.snibgo.com
coolperez8
Posts: 27
Joined: 2016-03-11T07:27:11-07:00
Authentication code: 1151

Re: Extract Transparent Foreground From Image

Post by coolperez8 »

snibgo wrote:How about:

Code: Select all

convert in.png -alpha transparent out.png
That did not work, it just made the entire image transparent.

Plus, I am trying to remove a known background of an image that has a transparent foreground.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract Transparent Foreground From Image

Post by fmw42 »

If you just want the alpha channel of the image (transparency) use

Code: Select all

convert image.png -alpha extractf alphachannel.png
coolperez8
Posts: 27
Joined: 2016-03-11T07:27:11-07:00
Authentication code: 1151

Re: Extract Transparent Foreground From Image

Post by coolperez8 »

fmw42 wrote:If you just want the alpha channel of the image (transparency) use

Code: Select all

convert image.png -alpha extractf alphachannel.png
Actually, what I'm trying to do is remove a known background from an image, although the foreground is transparent.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract Transparent Foreground From Image

Post by fmw42 »

If you remove the background channels, all you are left with is the alpha channel.

If you want the background area of the image to be removed in the sense of making it black (or white or some other color), leaving the opaque foreground and transparency still where the background exists, then use

Code: Select all

convert image -background black -alpha background result
Post Reply