How to plot png images with transparent background?
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (1)
Mr M.
il 12 Apr 2018
0 voti
2 Commenti
Cris LaPierre
il 11 Set 2019
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')
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.

Categorie
Scopri di più su Lighting, Transparency, and Shading in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!