MATLAB: Superimposing images (maps) with different colour scales and transparency/masking

colourcolour scalecombinegrayimagemapmaskoverlaysemi-transparent

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.

Best Answer

Bimage = get(gray_map_B, 'CData');
set(gray_map_B, 'AlphaData', 0.3 * (Bimage == 1));