How do you read the alpha channel of an indexed image?
8 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Guillaume
on 8 Dec 2017
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;
2 Comments
Guillaume
on 27 Nov 2018
For information, the bug has been fixed in R2018b.
[img, map, alpha] = imread('Dallas_Fuel_logo_std.png')
now correctly returns the transparency in alpha.
More Answers (0)
See Also
Categories
Find more on Modify Image Colors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!