How do you read the alpha channel of an indexed image?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Guillaume
le 8 Déc 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 commentaires
Guillaume
le 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Modify Image Colors dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!