Problem extracting alpha channel from indexed palette PNGs

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
vtagle-qsi
Posts: 12
Joined: 2008-09-05T16:30:03-07:00

Problem extracting alpha channel from indexed palette PNGs

Post by vtagle-qsi »

Hello,

I have a PNG file with an indexed palette and I'm trying to extract the alpha channel to use as an image mask but all the usual techniques I've tried have failed. Is there some trick to doing it? The best I can figure is I have to convert it to RGB but I can't seem to do that without losing the alpha channel completely.

Edit: Updated the subject to be more clear.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem extracting alpha channel from indexed palette PN

Post by fmw42 »

What version of IM are you using? PNG has undergone much developement over the last few months.

This works for me on IM 6.7.2.3 Q16 Mac OSX Tiger

# create 8-bit png with transparency
convert logo: -transparent white PNG8:logotp.png

# verify it
Identify -verbose logotp.png
Image: logotp.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 640x480+0+0
Resolution: 72x72
Print size: 8.88889x6.66667
Units: Undefined
Type: PaletteMatte
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 1-bit
Channel statistics:
Red:
min: 4 (0.0156863)
max: 255 (1)
mean: 229.323 (0.899307)
standard deviation: 69.3423 (0.271931)
kurtosis: 4.45973
skewness: -2.49768
Green:
min: 0 (0)
max: 255 (1)
mean: 226.217 (0.887127)
standard deviation: 70.8689 (0.277917)
kurtosis: 3.37246
skewness: -2.24758
Blue:
min: 0 (0)
max: 255 (1)
mean: 229.064 (0.898288)
standard deviation: 64.1018 (0.251379)
kurtosis: 4.65272
skewness: -2.42185
Alpha:
min: 0 (0)
max: 255 (1)
mean: 42.2975 (0.165872)
standard deviation: 94.8513 (0.371966)
kurtosis: 1.22759
skewness: -1.79655


# extract the alpha transparency data
convert logotp.png -alpha extract logotp_alpha.png
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Problem extracting alpha channel from indexed palette PN

Post by glennrp »

You would need to convert it to RGBA not RGB

Code: Select all

convert toucan.png png32:toucan_rgba.png
What command did you use to try to extract the alpha channel?
What version of IM do you have?
(BTW: toucan.png is found in the libpng distribution, gregbook directory).
vtagle-qsi
Posts: 12
Joined: 2008-09-05T16:30:03-07:00

Re: Problem extracting alpha channel from indexed palette PN

Post by vtagle-qsi »

Doh! The version of ImageMagick I was using was older than I thought (v6.6.something or other). Upgrading to the latest version fixes the problem.
Post Reply