How can I overlay pseudocolor images with different colormaps?
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Laurent G
el 9 de Mzo. de 2016
Respondida: Isaac Breinyn
el 16 de Jun. de 2019
Using Matlab R2015b with OpenGL rendering, I am trying to superimpose two pseudocolor images associated with different colormaps. Both images correspond to matrices displayed using imagesc. The commands are the following:
% Examples of matrices x=linspace(-7,7,200);y=x;[X,Y]=meshgrid(x,y);Z1=(X.^2+Y.^2).*exp(-(X.^2+Y.^2)/3^2);Z2=exp(-X.^2-Y.^2);
% New figure
hf=figure;
% Background image
h1 = axes;colormap(h1,'parula');p1=imagesc(x,y,Z1);set(h1,'ydir','normal');
% Foreground image
h2=axes;set(h2,'color','none','visible','off');colormap(h2,'jet');p2=imagesc(x,y,Z2,'alphadata',Z2>1e-2);set(h2,'ydir','normal');linkaxes([h1 h2])
I would like to display only the central part of the (Gaussian) matrix Z2, hence the transparency applied to its wings (with values < 1e-2). Doing so, the foreground image indeed gets paler, yet remains opaque to the background image. Actually, it remains opaque to the latter even by setting full transparency, i.e., set(p2,'alphadata',0)!
Consequently, I wonder whether it is possible at all to overlay pseudocolor images.
Thank you for your help.
0 comentarios
Respuesta aceptada
Mike Garrity
el 9 de Mzo. de 2016
Editada: Mike Garrity
el 9 de Mzo. de 2016
You actually have it exactly right, but the second call to imagesc reset the axes h2. This set the Visible property back to on. Just move this line:
set(h2,'color','none','visible','off');
Down to where you're doing this:
set(h2,'ydir','normal');
As long as an axes hold state is off, a plotting command will reset its properties. This means that changing properties on the axes before the plotting command doesn't work very well.
0 comentarios
Más respuestas (2)
Isaac Breinyn
el 16 de Jun. de 2019
For anyone else who remained confused for a moment, one must also move the line
colormap(h2, 'jet');
after imagesc, so that the working example is:
% Examples of matrices
x=linspace(-7,7,200);y=x;
[X,Y]=meshgrid(x,y);
Z1=(X.^2+Y.^2).*exp(-(X.^2+Y.^2)/3^2);
Z2=exp(-X.^2-Y.^2);
% New figure
hf=figure;
% Background image
h1 = axes;colormap(h1,'parula');
p1=imagesc(x,y,Z1);
set(h1,'ydir','normal');
% Foreground image
h2=axes;
p2=imagesc(x,y,Z2,'alphadata',Z2>1e-2);
set(h2,'color','none','visible','off')
colormap(h2,'jet');
set(h2,'ydir','normal');
linkaxes([h1 h2])
0 comentarios
Ver también
Categorías
Más información sobre Red en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!