Overlaid images: more than one axis in a subplot?

13 views (last 30 days)
I need to subplot two images that are overlaid. I only managed to overlay them using two axis for the same figure (note that both fifgures have it's own colormap). But now I need to subplot 6 pairs of overlaid images... I can't find the way of subplotting two axis in a subplot.
I need to overlaid some pixels of a a color image (activation level) over a background in black and white. This is what I did to overlaid:
Cmap = data.activmap(:,:,600,20); % image of activation to plot
backgr = data.backgr(:,:); %background image
backim= mat2gray(backgr); imshow(backim)
figure; % I need this one in a subplot (together with other similar)
ax1 = axes;
imagesc(backgr);
colormap(ax1,'bone');
ax2 = axes;
imagesc(ax2,Cmap,'alphadata',Cmap>0.02);
colormap(ax2,polarmap(jet));
caxis(ax2,[min(nonzeros(Cmap)) max(nonzeros(Cmap))]);
ax2.Visible = 'off';
linkprop([ax1 ax2],'Position');
colorbar;
I have unsuccessfully tried some alternatives.. could anyone give me a hand? (thanks)
  2 Comments
Tamara del Águila
Tamara del Águila on 12 Nov 2020
Interesting... but how could I implement it with images?
(thanks for answering)

Sign in to comment.

Answers (1)

Tamara del Águila
Tamara del Águila on 12 Nov 2020
Edited: Tamara del Águila on 12 Nov 2020
Right after asking, I came up myself with one solution... (had I known I would have asked before!).
What I did was a function in which I pass the subplot axis handle as an input, and then inside the function I align them all respect to the input axis handle...
If anyone knows a better solution, I'll be pleased to listen to it!
Cmap = VSDmoviep10.data(:,:,600,20); %colorimage (to overlaid pixels above threshold)
backgr = VSDI.backgr(:,:,1); % black&white background
backim= mat2gray(backgr);
% threshold above which to plot Cmap
thresh = 0.02 %
fig=figure;
ax1 = subplot(2,2,3);
plot_framesoverlaid(Cmap, backgr, thresh , ax1);
And the function:
function plot_framesoverlaid(imAct, imBack, thresh, plotnow, axH)
% Overlay colormap over greyscale background
ax1 = axes;
imagesc(imBack);
colormap(ax1,'bone');
ax2 = axes;
imagesc(ax2,imAct,'alphadata',imAct>thresh);
colormap(ax2,polarmap(jet));
caxis(ax2,[min(nonzeros(imAct)) max(nonzeros(imAct))]);
ax2.Visible = 'off';
colorbar;
linkprop([axH ax1 ax2],'Position');
end
  2 Comments
Akira Agata
Akira Agata on 13 Nov 2020
Thank you for clarifying your question and providing your code. But, unfortunately, I couldn't run your code and came across some errors.
If possible, could you provide what the desired output looks like?
Tamara del Águila
Tamara del Águila on 13 Nov 2020
Sure!
By the way, I just noticed that I forgot to remove the input 'plotnow' from that simplified version I posted before.
I also copy the final function I am working with at the end of the response. I have changed the input 'threshold' by an 'logicalpha' (transparency) matrix . And this is how it looks:
( I have not adapted the function to the case in which the handle is not provided, but can be easily done)
function plot_framesoverlaid(imAct, imBack, logicalpha, plotnow, axH, act_clim, plot_cbar)
% Overlay an color image over a background
% INPUT
% 'imAct' - image to display in colors
% 'imBack' - background image
% 'logicalpha': logic matrix with transparency information (1 = shown pixel)
% 'plotnow': whether we want to plot the figure (set to 0 if we are providing a axisHandle)
% 'axH': axes handle in which to plot it, when it's going to be included into a subplot
% 'act_clim': color limits for 'imAct'. If no color limits is provided for the activity (color) map, use the max
% and min from the input movie
% 'plot_cbar' : whether we want to plot the colorbar (useful in subplots)
if ~exist('act_clim')
act_clim = [min(nonzeros(imAct(:))) max(nonzeros(imAct(:)))];
elseif isempty(act_clim)
act_clim = [min(nonzeros(imAct(:))) max(nonzeros(imAct(:)))];
end
if ~exist('thresh')
thresh = 0;
elseif isempty(thresh)
thresh = 0;
end
if ~exist('plotnow')
plotnow= 1;
elseif isempty(plotnow)
plotnow= 1;
end
if ~exist('plot_cbar')
plot_cbar= 1;
elseif isempty(plot_cbar)
plot_cbar= 1;
end
% end of input control ------------------------
if plotnow
fig1 = figure;
end
ax1 = axes;
imagesc(imBack);
colormap(ax1,'bone');
ax1.Visible = 'off';
ax2 = axes;
% imagesc(ax2,imAct,'alphadata',imAct>thresh);
imagesc(ax2,imAct,'alphadata',logicalpha);
colormap(ax2,polarmap(jet));
caxis(ax2, act_clim);
ax2.Visible = 'off';
if plot_cbar
colorbar;
end
linkprop([axH ax1 ax2],'Position');
end

Sign in to comment.

Categories

Find more on Axes Appearance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!