Code covered by the BSD License  

Highlights from
Display multiple images on individual axes and optionally link them

image thumbnail

Display multiple images on individual axes and optionally link them

by

 

imagecat generates a 'catalog' of images useful for visualizing steps in image processing.

h=imagecat(varargin)
function h=imagecat(varargin)
% ImageCat displays a 'catalog' of images on individual axes and optionally
% links the axes.
%
% IMAGECAT(I1,...) generates a simultaneous display of multiple images on
% individual axes.
% 
% IMAGECAT(x,y,I1,...) displays all the images over axes defined by vectors
% x and y.
% 
% IMAGECAT(...,'link') links all image axes (see linkaxes).
% IMAGECAT(...,'xy') displays all axes with xy orientation (see axis xy)
% IMAGECAT(...,'equal') sets the axes to be proportional (see axis equal)
%
% First two arguments (x,y) and last three arguments ('link','xy','equal')
% are optional. Last three arguments can be issued in any order after the
% image arguments.
% 
% Usage example:
% 
% See also:
% montage, axis, linkaxes.
%
% Author: Shalin Mehta (www.mshalin.com) 
% License: BSD 
% Version history: March 2011, initial implementation.
%                  June 2012, optional linking, axis xy, axis equal.
%                  Feb 2013, improved error checking and included usage example.



if(nargin < 2)
    error('Atleast two images are required.');
end

% The first two arguments may be axes of the images.
% imageidx lists the indices of images in varargin.
if(isvector(varargin{1}) && isvector(varargin{2}))
    x=varargin{1};
    y=varargin{2};
    imageidx=3:length(varargin); 
else
    x=1:size(varargin{1},2);
    y=1:size(varargin{1},1);
    imageidx=1:length(varargin);
end


% The last three arguments may be 'link', 'xy', 'equal'.
lastimageidx=nargin-3;
if(lastimageidx<1) 
    lastimageidx=1;
end
    
if(any(cellfun(@(x) strcmp(x,'link'), varargin(lastimageidx+1:end))))
    linkplots=true;
    imageidx=imageidx(1:end-1);
else 
    linkplots=false;
end

if(any(cellfun(@(x) strcmp(x,'xy'), varargin(lastimageidx+1:end))))
    plotxy=true;
    imageidx=imageidx(1:end-1);
else
    plotxy=false;
end

if(any(cellfun(@(x) strcmp(x,'equal'), varargin(lastimageidx+1:end))))
    axiseq=true;
    imageidx=imageidx(1:end-1);
else
    axiseq=false;
end

% Make sure that all other arguments are images.
ismatrixvector=cellfun(@(x) ismatrix(x),varargin(imageidx));
if(~all(ismatrixvector))
    error('One or more of the inputs that should be image are not images.');
end

h=zeros(size(imageidx));
numcols=ceil(length(imageidx)/2);

for n=1:length(imageidx)
    h(n)=subplot(2,numcols,n); 
    
    imagesc(x,y,varargin{imageidx(n)}); colorbar;
    title(inputname(imageidx(n)));
    
    if(plotxy)
        axis xy;
    end
    
    if(axiseq);
        axis equal;
    end
    
    axis tight;
end

if(linkplots)
    linkaxes(h);
end

end

Contact us