How to make one color transparent in a PNG?

조회 수: 7 (최근 30일)
Marina
Marina 2019년 11월 1일
답변: Walter Roberson 2019년 11월 4일
Hi, I am making maps and want to have the land transparent to then overlay over Google maps. The way around it I think is to creat the figure with land in black (as nothing else in the image is black) and the have that color made trasnaprent. I have not been able to do this so far... Here's the code, I appreciate anyone pointing me in the right direction. thanks
Screen Shot 2019-11-01 at 1.25.15 PM.png
  댓글 수: 2
the cyclist
the cyclist 2019년 11월 1일
It's better to paste code than an image of code. Otherwise, if someone wants to try it out, they need to retype everything.
Marina
Marina 2019년 11월 1일
yes sorry,
fh=figure %('Menu','none','ToolBar','none ');
ah=axes('Units','Normalize','Position',[0 0 1 1])
axis(ah, 'square')
fh.Position(3) = fh.Position(4); %set width equal to height
m_proj('mercator','longitudes',[-96,-76.5],'latitud',[1,20]);
hold on
fig=m_contourf(long,lati,speed,V,'LineColor','none');
colormap(jet)
caxis([0 0.7])
fig = m_quiver(long,lati,outstrct.u(idx_lon,idx_lat),outstrct.v(idx_lon,idx_lat),8,'k','LineWidth',0.5);
m_gshhs_h('patch',[0 0 0]); % searches for the GSHHS database in /m_map/private. Sets land to black.
m_grid('box','off', 'LineStyle','none','xticklabels',[],'yticklabels',[],'xtick',[],'ytick',[]);
print('/Users/marinam_ar/Desktop/OPERATIONAL/MAPS_JEFF5_TRANSP/CURRENTS_Oct272019','-dpng','-r1200')

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

답변 (2개)

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi 2019년 11월 4일
You can change the transparency of a color in an image using AlphaData property. The following link has an example
In order to change the transparency of an object on an axis you can use ‘alpha’ property. For more information refer to the following link
Hope this helps!

Walter Roberson
Walter Roberson 2019년 11월 4일
print() to the png file. Then read in the file and write out a new copy of it that has the appropriate color set as transparent. See

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by