Superimposing images (maps) with different colour scales and transparency/masking?
조회 수: 3 (최근 30일)
이전 댓글 표시
I am trying to plot two maps (same size) on top of each other, where the first one is in colour scale and the second one is in gray-scale, semitransparent (or hatched pattern)
I would like to display input_A as a regular map with colour scale jet(15). Next, I would like to superimpose input_B of the same size and on the same axis, which consists of only two values (0 and 1), plotted in semi-transparent gray for cell values of 1 only.
(If the value of input_B is 0, the cell should be fully transparent (showing only input_A in the end plot) and if the cell value of input_B is 1, it should be semi-transparent fill, so that on the final figure shows input_A with a dot shaded in gray from input_B).
%To plot map_A, I’m using the code:
colour_map_A=image(min(longitude):3.6:max(longitude),max(latitude):-1.8:min(latitude),input_A,'CDataMapping','scaled')
caxis(scale_A) %scale_A=[-100,100];
colormap(flipud(jet(15)))
axis equal
box on
set(gca,'XLim',[min(longitude) max(longitude],'YLim',[min(latitude) max(latitude)], ...
'XTick',[0 60 120 180 240 300 360], ...
'Ytick',[-90 -60 -30 0 30 60 90]);
xlabel('Longitude')
ylabel('Latitude')
% load topographic data
load('topo.mat','topo');
% plot coast lines
hold on
contour(0:359,90:-1:-89,topo,[0,0],'k')
hold on
gray_map_B=image(min(longitude):3.6:max(longitude),max(latitude):-1.8:min(latitude),input_B,'CDataMapping','scaled')
caxis(scale_B) %scale_B=[0,1];
colormap(flipud(gray(2)))
alpha=0.3; %however, this makes both plots semi-transparent, not only the second one.
Also, if I plot gray_map_B on top of colour_map_A, the colour scale changes for both maps to gray and gray_map_B covers colour_map_A.
In the end, I’m looking for a way of plotting input_A as it is in colour map, and superimposing input_B in a semi-transparent gray only for cell values of 1 only.
댓글 수: 1
Image Analyst
2015년 8월 14일
Attach input_A, input_B, and the 'topo.mat' file so people can try to help you.
채택된 답변
Walter Roberson
2015년 8월 10일
Bimage = get(gray_map_B, 'CData');
set(gray_map_B, 'AlphaData', 0.3 * (Bimage == 1));
추가 답변 (1개)
Image Analyst
2015년 8월 11일
댓글 수: 3
Harry Farmer
2016년 4월 18일
Hi,
I was wondering if you ever managed to resolve the "'AlphaData' property of Image: Value must be a scalar, vector or array of numeric or logical type" error you were getting. I'm trying to do something quite a bit more simple than you (just making one image transparent using another image's alpha mask, but am getting this message and can't find anything on the internet that would indicate why. Infact yours is the only report of this error I can find online.
Walter Roberson
2016년 4월 18일
In the above code, Bimage is 3D, so Bimage == 1 is 3D, and AlphaData cannot be 3D. The above code should use
set(h, 'AlphaData', 0.1 * (size(Bimage,1), size(Bimage,2)));
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!