Superimposing images (maps) with different colour scales and transparency/masking?
8 views (last 30 days)
Show older comments
k78na
on 10 Aug 2015
Commented: Walter Roberson
on 18 Apr 2016
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 Comment
Image Analyst
on 14 Aug 2015
Attach input_A, input_B, and the 'topo.mat' file so people can try to help you.
Accepted Answer
Walter Roberson
on 10 Aug 2015
Bimage = get(gray_map_B, 'CData');
set(gray_map_B, 'AlphaData', 0.3 * (Bimage == 1));
More Answers (1)
Image Analyst
on 11 Aug 2015
3 Comments
Harry Farmer
on 18 Apr 2016
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
on 18 Apr 2016
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)));
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!