MATLAB: How do you read the alpha channel of an indexed image

alpha channelimreadindexed imagetransparency

Imread or open seems to give you only the cdata + colormap, however if there is transparency in the image, I can't read the information with matlab.
Is there any way to get the alpha channel?

Best Answer

Hum, yes it does appear that you cannot retrieve the alpha value associated with the palette of a png image with imread. I think that is worthy of a bug report to mathworks.
You can still get the transparency info with imfinfo:
pnginfo = imfinfo('Dallas_Fuel_logo_std.png');
pnginfo.SimpleTransparencyData
Note:
The transparency for png indexed image is stored in a tRNS chunk. The length of the transparency array is at most the length of the colour map but can be shorter (as is the case in your image). In that case, the remaining colours all have 0 transparency. Consequently, I would read the transparency as follow:
[img, map] = imread(pngpath);
pnginfo = imfinfo(pngpath);
maptrans = zeros(size(map, 1), 1);
maptrans(1:numel(pnginfo.SimpleTransparencyData)) = pnginfo.SimpleTransparencyData;