Can a PNG image be displayed without displaying the black fill in the guide?
Show older comments
I want to show a PNG image without a background but when I put it in the guide I fill it with the color of black
5 Comments
Image Analyst
on 5 Nov 2017
What color did you want? Did you try making the color of the figure and the color of the axes background the same?
Erwin Avendaño
on 5 Nov 2017
Guillaume
on 5 Nov 2017
Your question is really not clear. What background are you talking about?
Are you actually asking how to handle a PNG with a transparency channel (or a transparent colour)? And wanting that transparency to be applied correctly?
Erwin Avendaño
on 6 Nov 2017
Erwin Avendaño
on 6 Nov 2017
Answers (2)
Walter Roberson
on 6 Nov 2017
When you image() or imagesc() or imshow(), pass an option 'AlphaData' that is an array with the desired transparency, with 1 meaning to show the image completely and 0 meaning not showing the image at all (that is, show the background completely there.)
If the PNG had alpha information stored with it that you read with imread() then you should be able to use that transparency information directly.
[YourImage, ~, ImageAlpha] = imread('YourFile.png');
image(YourImage, 'AlphaData', ImageAlpha)
3 Comments
giannit
on 24 Apr 2021
@Walter Roberson i tried it with imshow() in R2021a but gives error: The parameter, AlphaData, is not recognized by imageDisplayParsePVPairs
Walter Roberson
on 24 Apr 2021
Ah, in that case use image(), or use
[YourImage, ~, ImageAlpha] = imread('YourFile.png');
h = imshow(YourImage);
h.AlphaData = ImageAlpha;
giannit
on 24 Apr 2021
@Walter Roberson yes i need imshow(), many thanks walter you are da real mvp
Joseph Stover
on 9 Mar 2021
0 votes
I was just having a similar problem and I was able to fix it by opening each png in paint.net and saving it as a 24 bit png.
1 Comment
Sebastian Cuenca
on 16 Jun 2021
mmm I tried it but it just set a white background on image...
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!