How can I overlay pseudocolor images with different colormaps?
24 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Mike Garrity
2016-3-9
编辑:Mike Garrity
2016-3-9
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 个评论
更多回答(2 个)
Isaac Breinyn
2019-6-16
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Red 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!