質問

So I have this transparent image (http://imgur.com/fyqslAx) that I want to display on an axes in MATLAB with its transperancy. To do this, I used the code below, which works with other transparent png images that I have:

[A, map, alpha] = imread('fyqslAx.png');
h = imshow(A, map)
set(h, 'AlphaData', alpha);

This code however, does not seem to work with the image above. Im guessing this is because it has something to do with the image being grayscale and having a bitdepth of 1, resulting in the map and alpha having nothing in it (whereas the other png transparent images I have, have something in map and alpha). If I just use this:

A = imread('fyqslAx.png');
h = imshow(A)

A black background appears where the image should be transparent.

How do I display this http://imgur.com/fyqslAx with its transperancy on an axes?

EDIT: horchler's method worked; Thanks!!

役に立ちましたか?

解決

If you run imfinfo('fyqslAx.png'), you'll see that the 'Transparency' is specified as 'simple' and the 'SimpleTransparencyData' is set to 0 (false). I can't find documentation on this, but I think that this may indicate that the alpha channel has been compressed into the image data because the the image is binary and grayscale. Effectively the image is a binary mask, either transparent or not. You can display your image like this:

A = imread('fyqslAx.png');
h = imshow(A);
set(h, 'AlphaData', A);

If you try to return a colormap and/or alpha channel from imread using extra output arguments, you'll see that both are empty.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top