How to plot png images with transparent background?
155 ビュー (過去 30 日間)
古いコメントを表示
I've just used image(), and the transparent area are shown with black colour by default, however I need white background. I tried to use set(gcf,'color','white') but this cannot help.
0 件のコメント
採用された回答
Walter Roberson
2018 年 4 月 12 日
When you image() pass in 'AlphaData', and the transparency data. The alpha needs to be floating point (not logical) in the range 0 to 1 and the same size as the image.
1 件のコメント
Walter Roberson
2018 年 4 月 12 日
[img, map, alphachannel] = imread('YourImage.png');
image(img, 'AlphaData', alphachannel);
その他の回答 (1 件)
Mr M.
2018 年 4 月 12 日
2 件のコメント
Cris LaPierre
2019 年 9 月 11 日
Images get displayed in an axes. Even if the image doesn't have a background, it will at least originally display in an axes with a background color set to white. You can turn that off using
axis off
of
set(gca,'Color','none')
DGM
2022 年 11 月 3 日
編集済み: DGM
2022 年 11 月 3 日
If you're trying to retain the original alpha content from the PNG file:
% read the image and its alpha
[inpict,~,alpha] = imread('peppers_rgba.png');
% show the image with the alpha from the file
image(inpict,'alphadata',im2double(alpha))
% set the axes background color if desired
set(gca,'color',[0.8 0.3 1])
If instead, your concern is how the transparent regions are visualized, then consider this example regarding display matting for transparent images.
参考
カテゴリ
Help Center および File Exchange で Lighting, Transparency, and Shading についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!