Created
December 6, 2012 19:07
-
-
Save Higgcz/4227257 to your computer and use it in GitHub Desktop.
Montage functiong for displaying multiple images as grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function montage(images, varargin) | |
%MONTAGE Display multiple images as grid | |
% | |
% Synopsis: | |
% MYMONTAGE(images) | |
% MYMONTAGE(...,PARAM1,VAL1,PARAM2,VAL2,...) displays the image, specifying | |
% parameters and corresponding values that control various aspects of the | |
% image display. Parameter names can be abbreviated, and case does not matter. | |
% | |
% Parameters include: | |
% | |
% 'Border' String that controls whether | |
% a border is displayed around the image in the | |
% figure window. Valid strings are 'tight' and | |
% 'loose'. | |
% | |
% Note: There can still be a border if the image | |
% is very small, or if there are other objects | |
% besides the image and its axes in the figure. | |
% | |
% By default, the border is set to the value | |
% returned by | |
% IPTGETPREF('ImshowBorder'). | |
% | |
% 'Colormap' 2-D, real, M-by-3 matrix specifying a colormap. | |
% IMSHOW uses this to set the figure's colormap | |
% property. Use this parameter to view grayscale | |
% images in false color. | |
% | |
% 'DisplayRange' Two-element vector [LOW HIGH] that controls the | |
% display range of a grayscale image. See above | |
% for more details about how to set [LOW HIGH]. | |
% | |
% Including the parameter name is optional, except | |
% when the image is specified by a filename. | |
% The syntax IMSHOW(I,[LOW HIGH]) is equivalent to | |
% IMSHOW(I,'DisplayRange',[LOW HIGH]). | |
% The parameter name must be specified when | |
% using IMSHOW with a filename, as in the syntax | |
% IMSHOW(FILENAME,'DisplayRange'[LOW HIGH]). | |
% | |
% 'InitialMagnification' A numeric scalar value, or the text string 'fit', | |
% that specifies the initial magnification used to | |
% display the image. When set to 100, the image is | |
% displayed at 100% magnification. When set to | |
% 'fit' IMSHOW scales the entire image to fit in | |
% the window. | |
% | |
% On initial display, the entire image is visible. | |
% If the magnification value would create an image | |
% that is too large to display on the screen, | |
% IMSHOW warns and displays the image at the | |
% largest magnification that fits on the screen. | |
% | |
% By default, the initial magnification is set to | |
% the value returned by | |
% IPTGETPREF('ImshowInitialMagnification'). | |
% | |
% If the image is displayed in a figure with its | |
% 'WindowStyle' property set to 'docked', then | |
% IMSHOW warns and displays the image at the | |
% largest magnification that fits in the figure. | |
% | |
% Note: If you specify the axes position (using | |
% subplot or axes), imshow ignores any initial | |
% magnification you might have specified and | |
% defaults to the 'fit' behavior. | |
% | |
% When used with the 'Reduce' parameter, only | |
% 'fit' is allowed as an initial magnification. | |
% | |
% 'Parent' Handle of an axes that specifies | |
% the parent of the image object created | |
% by IMSHOW. | |
% | |
% 'Reduce' Logical value that specifies whether IMSHOW | |
% subsamples the image in FILENAME. The 'Reduce' | |
% parameter is only valid for TIFF images and | |
% you must specify a filename. Use this | |
% parameter to display overviews of very large | |
% images. | |
% | |
% 'XData' Two-element vector that establishes a | |
% nondefault spatial coordinate system by | |
% specifying the image XData. The value can | |
% have more than 2 elements, but only the first | |
% and last elements are actually used. | |
% | |
% 'YData' Two-element vector that establishes a | |
% nondefault spatial coordinate system by | |
% specifying the image YData. The value can | |
% have more than 2 elements, but only the first | |
% and last elements are actually used. | |
% | |
% See also IMSHOW | |
% | |
[dimx dimy num] = size(images); | |
numOfCols = ceil(sqrt(num)); | |
horims = []; | |
for iy=1:(numOfCols-1), | |
verims = []; | |
for ix=1:(numOfCols), | |
realIndex = ix * iy; | |
if ( realIndex < num ), | |
image = images(:,:,realIndex); | |
else | |
image = zeros(dimx, dimy); | |
end; | |
verims = horzcat(verims, image); | |
end; | |
horims = vertcat(horims, verims); | |
end; | |
imshow(horims, varargin); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment