I have a transparent .png picture when I add it to the current figure the background of it changes to black!

31 views (last 30 days)
Hey all, I wanted to add a picture of my current figure. The picture is transparent png but when I added to my figure a black background appears with it. please see the picture below (in this picture the 2 png pictures are 2 small colorful circles and the current figure is a map of country:
This happening while my circle is png and transparent:
I don't know what is this black background, I want to delete it. The code that I used is:
%read map (tif file)
[A,R] = readgeoraster('DEM_30s.tif', 'OutputType', 'double');
low_single = typecast(uint8([255 255 127 255]), 'single');
mask = low_single==A;
A = A - min(A(~mask), [], 'all');
% creating colormap changing from white to brown as shown in image in the question
brown_color = [0.8 0.2 0.1];
light_brown = [0.95 0.9 0.8];
t = linspace(0, 1, max(A,[],'all'))';
cmap = t.*brown_color + (1-t).*light_brown;
% plot tif file
gs = geoshow(A, cmap, R);
gs.CData(repmat(mask,1,1,3)) = 255;
axis equal
box on
hold on
% read small circle
img = imread('filename1.png');
image('CData',img,'XData',[50 52],'YData',[30 32])
hold off

Accepted Answer

Ameer Hamza
Ameer Hamza on 13 Apr 2020
Edited: Ameer Hamza on 13 Apr 2020
Read the transperancy map and use it to make the background transparent.
% read small circle
[img, ~, tr] = imread('test.png');
im = image('CData',img,'XData',[50 52],'YData',[30 32]);
im.AlphaData = tr;
hold off

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!