⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 montage.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
字号:
function h = montage(a,cm)
%MONTAGE Display multiple image frames as rectangular montage.
%   MONTAGE displays all the frames of a multiframe image array
%   in a single image object, arranging the frames so that they
%   roughly form a square.
%
%   MONTAGE(I) displays the K frames of the intensity image array
%   I. I is M-by-N-by-1-by-K.
%
%   MONTAGE(BW) displays the K frames of the binary image array
%   BW. BW is M-by-N-by-1-by-K.
%
%   MONTAGE(X,MAP) displays the K frames of the indexed image
%   array X, using the colormap MAP for all frames. X is
%   M-by-N-by-1-by-K.
%
%   MONTAGE(RGB) displays the K frames of the truecolor image
%   array RGB. RGB is M-by-N-by-3-by-K.
%
%   H = MONTAGE(...) returns the handle to the image object.
%
%   Class support
%   -------------
%   The input image can be of class uint8 or double.
%
%   Example
%   -------
%       load mri
%       montage(D,map)
%
%   See also IMMOVIE.

%   Clay M. Thompson 5-13-93
%   Revised for IPT v2 by Steven L. Eddins, September 1996
%   Copyright 1993-1998 The MathWorks, Inc.  All Rights Reserved.
%   $Revision: 5.9 $  $Date: 1997/11/24 15:35:58 $

if (nargin == 0)
    error('Not enough input arguments');
end

if ((nargin == 2) & (size(cm,1) == 1) & (prod(cm) == prod(size(a))))
    % old-style syntax
    % MONTAGE(D,[M N P])
    siz = cm;
    a = reshape(a,[siz(1) siz(2) 1 siz(3)]);
    if (isind(a(imslice(siz,1))))
        cm = colormap;
        hh = montage(a,cm);
    else
        hh = montage(a);
    end
    
else

    siz = [size(a,1) size(a,2) size(a,4)];
    nn = sqrt(prod(siz))/siz(2);
    mm = siz(3)/nn;
    if (ceil(nn)-nn) < (ceil(mm)-mm),
        nn = ceil(nn); mm = ceil(siz(3)/nn);
    else
        mm = ceil(mm); nn = ceil(siz(3)/mm);
    end
    
    b = a(1,1); % to inherit type 
    b(1,1) = 0; % from a
    b = repmat(b, [mm*siz(1), nn*siz(2), size(a,3) 1]);

    rows = 1:siz(1); cols = 1:siz(2);
    for i=0:mm-1,
        for j=0:nn-1,
            k = j+i*nn+1;
            if k<=siz(3),
                b(rows+i*siz(1),cols+j*siz(2),:) = a(:,:,:,k);
            end
        end
    end
    
    if (nargin == 1)
        hh = imshow(b);
        
    elseif (nargin == 2)
        hh = imshow(b,cm);
        
    else
        error('Too many input arguments');
    end
    
end

if nargout > 0
    h = hh;
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -