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

9 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 10 Ago 2015
Bimage = get(gray_map_B, 'CData');
set(gray_map_B, 'AlphaData', 0.3 * (Bimage == 1));
  1 Commento
k78na
k78na il 11 Ago 2015
thank you, it seems to work for part of my question, but it uses the colormap of the original image and fades it out for some cells, as needed. However, I would like to create a faded "mask" of a different colour (semi-transparent, on top of the original image), rather than shading the original image.
I tried
set(gray_map_B, 'AlphaData', 0.3 * (Bimage == 1));
hold on;
set(gray_map_B, 'Colormap',mycmap_gray)
(or I could just use build-in colour map gray(2) to have gray shading on the mask)
However, this gives an error:
Error using matlab.graphics.primitive.Image/set
There is no Colormap property on the Image class.
On the other hand, using
set(figure(1),'Colormap',mycmap_gray)
changes color maps of both images, while I only wanted to change the colour of the created mask (gray_map_B).
Would you have any suggestions on how to set different colormap for gray_map_B, without impacting the colour_map_A?

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 11 Ago 2015
  3 Commenti
Harry Farmer
Harry Farmer il 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
Walter Roberson il 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)));

Accedi per commentare.

Categorie

Scopri di più su Images in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by