Why does imread read the alpha channel, but not the image itself?
49 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all,
I would like to read a png with transparent background in MATLAB (2014b, Windows 7) using imread:
[icon, map, alpha] = imread('icon.png');
However, icon is now only zeros, but the alpha channel is read correctly (the map is empty as well). I made the png with Photoshop and I tried several options, such as making the image indexed, RGB, grayscale, 8 bits, 32 bits, et cetera.
Does anyone have an idea about why my alpha channel is read correctly, but the image data is black? How should I save the image from Photoshop such that it is read in MATLAB? Thanks in advance!
Kind regards, Mark
0 commentaires
Réponse acceptée
DGM
le 11 Avr 2022
Old question, I know, but I answer them when I'm bored.
The reason that the image looks all black is because that's what it is. The color content is a uniform black field. The object content of the image is defined only by the alpha channel. There isn't any reason to suspect that transparent image regions are any particular color.
It's worth noting that this might not always seem to be the case. Consider a modified version of the same image. In this case, the color channels are a uniform purple field. The alpha channel is the same as before. I've scaled the image to make it easier to see. What happens if you try to just load the color content? You should get a uniform purple field, right?
A = imread('icon.png');
imshow(A)
Nope. This doesn't mean that the color content is black and purple. There is no black in the image, but when called with this syntax, imread() internally composes the transparent image with a black field, resulting in this. It may be a convenience, but it's inflexible and misleading, so pay attention. If your images have alpha content, you must call imread with three output arguments in order to get unadulterated color content for the image, even if you don't need to use the alpha for anything.
0 commentaires
Plus de réponses (1)
Raphael
le 6 Avr 2018
Modifié(e) : Walter Roberson
le 7 Avr 2018
1 commentaire
Walter Roberson
le 7 Avr 2018
Notice, though, that "icon is now only zeros", so something else was going wrong for the user.
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!