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

조회 수: 31 (최근 30일)
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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 13일
편집: Ameer Hamza 2020년 4월 13일
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
  댓글 수: 2
BN
BN 2020년 4월 13일
편집: BN 2020년 4월 13일
Really Thank you it's fixed now.
Just one thing, the circle rotated! because in the main png is:
But after adding it to figure it is rotated!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by