Extract an Alpha channel

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
lilith
Posts: 8
Joined: 2010-10-06T23:37:50-07:00
Authentication code: 8675308

Extract an Alpha channel

Post by lilith »

Hi there,

I want to extract an alpha channel from RGBA file.
I used:

Code: Select all

convert -alpha extract "rgba.png" "alpha.png"
or

Code: Select all

convert -separate -channel a "rgba.png" "alpha.png"
It's not what i want.
The file: http://www.hostingpics.net/viewer.php?i ... mized1.png
What it does : http://www.hostingpics.net/viewer.php?i ... 1alpha.png
What i want : http://www.hostingpics.net/viewer.php?i ... ealpha.png

[
Edit:
Zoom:
ImageMagick gives : http://www.hostingpics.net/viewer.php?id=693425zoom.png
I want : http://www.hostingpics.net/viewer.php?i ... omtrue.png
]

Is that possible to get this from IM?
Thanks in advance.
Last edited by lilith on 2012-08-07T10:34:02-07:00, edited 3 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract an Alpha channel

Post by fmw42 »

Your IM syntax is not correct for IM 6. try putting the image before the options.

convert "rgba.png" -alpha extract "alpha.png"

The quotes are not really needed unless you have a space in the file names, though it should not hurt to leave them.

see
http://www.imagemagick.org/Usage/basics/#why
lilith
Posts: 8
Joined: 2010-10-06T23:37:50-07:00
Authentication code: 8675308

Re: Extract an Alpha channel

Post by lilith »

Hi fmw42,

Your code works too, but it's not what i want.

Thanks,
Greetings.

[
Edit:
ImageMagick gives : http://www.hostingpics.net/viewer.php?id=693425zoom.png
I want : http://www.hostingpics.net/viewer.php?i ... omtrue.png
]
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Extract an Alpha channel

Post by fmw42 »

The image you posted has no alpha channel. Perhaps it got removed when uploading or I am not downloading correctly.


Image: 693425zoom.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 854x650+0+0
Resolution: 72x72
Print size: 11.8611x9.02778
Units: Undefined
Type: TrueColor
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Red:
min: 0 (0)
max: 255 (1)
mean: 125.438 (0.491913)
standard deviation: 111.795 (0.438412)
kurtosis: -1.88083
skewness: 0.0740597
Green:
min: 0 (0)
max: 255 (1)
mean: 125.438 (0.491913)
standard deviation: 111.795 (0.438412)
kurtosis: -1.88083
skewness: 0.0740597
Blue:
min: 0 (0)
max: 255 (1)
mean: 129.79 (0.508981)
standard deviation: 112.132 (0.439732)
kurtosis: -1.86956
skewness: 0.0383976
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 126.889 (0.497603)
standard deviation: 111.907 (0.438852)
kurtosis: -1.87623
skewness: 0.0622613
lilith
Posts: 8
Joined: 2010-10-06T23:37:50-07:00
Authentication code: 8675308

Re: Extract an Alpha channel

Post by lilith »

Hello,

Hum sorry for confusing, but you did not scan the good file:
- The image that uses alpha is here: http://www.hostingpics.net/viewer.php?i ... mized1.png
- Here is the alpha data extracted by ImageMagick : http://www.hostingpics.net/viewer.php?i ... 1alpha.png
- Here is the alpha data extracted by another tool : http://www.hostingpics.net/viewer.php?i ... ealpha.png

Image Magick does not extract alpha correctly, because it seems it destroys some data! The difference is hard to see by eyes, so i zoomed on alpha datas:
- Zoom on alpha data extracted by ImageMagick : http://www.hostingpics.net/viewer.php?id=693425zoom.png
- Zoom on alpha data extracted by another tool : http://www.hostingpics.net/viewer.php?i ... omtrue.png

If i use alpha data extracted by ImageMagick as an alpha channel for the original file, that gives that:
http://www.hostingpics.net/viewer.php?i ... mized2.png

So, it's not the same restitution. There is a problem with alpha extraction, or i do not use the good option.

What i want is to extract alpha from this file:
http://www.hostingpics.net/viewer.php?i ... mized1.png
and get that result:
http://www.hostingpics.net/viewer.php?i ... ealpha.png

And i would like to do this with ImageMagick :)

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

Re: Extract an Alpha channel

Post by fmw42 »

You do not say what version of IM and platform you are using (or I missed it). But since IM 6.7.8.3 grayscale images have been linear rather than non-linear sRGB. So to get back what you expect you need to add -set colorspace RGB to your command as

convert 2101356optimized1.png -set colorspace RGB -alpha extract 2101356optimized1_alpha.png

This will get you back to what you want.
lilith
Posts: 8
Joined: 2010-10-06T23:37:50-07:00
Authentication code: 8675308

Re: Extract an Alpha channel

Post by lilith »

Hello,

I'm using 6.7.8.8.

And thanks, it works perfectly :)
Greetings.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Extract an Alpha channel

Post by anthony »

Alpha channel is always linear, so I don't know why you need such a convoluted colorspace!

Oh, I get it copying linear alpha into non-linear color channels. Making image RGB first fixes that!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply