Why does imread read the alpha channel, but not the image itself?

49 visualizaciones (últimos 30 días)
Mark
Mark el 20 de Nov. de 2014
Respondida: DGM el 11 de Abr. de 2022
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

Respuesta aceptada

DGM
DGM el 11 de Abr. de 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.

Más respuestas (1)

Raphael
Raphael el 6 de Abr. de 2018
Editada: Walter Roberson el 7 de Abr. de 2018
  1 comentario
Walter Roberson
Walter Roberson el 7 de Abr. de 2018
Notice, though, that "icon is now only zeros", so something else was going wrong for the user.

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by