gusucode.com > Matlab脸部识别程序源码 > code/code/dispset2d.m

    function [dvector, D] = dispset2d(imageset);
%
% simple demo function for CS 175 which displays a mosaic
% of images as specified by imageset
%
% Note that imageset is the standard CS 175 structure array
% for storing images


% define a boundary between the images
bdr = 10;

% find the number of images
[m n] = size(imageset);

% cycle through the images
count = 0;
for i=1:m
    for j= 1:n
       count = count + 1;
       % find the size of the image (this code effectively assumes
       % all images are the same size, with the exception of empty images
       [nx ny] = size(imageset(i,j).image);
       % if there is image data....
       if nx>0 & ny>0
          % temporarily rehape the image matrix as a vector
          dvector(count,:) = reshape(imageset(i,j).image, 1, nx*ny);
     	  else 
          count = count - 1;
     end
    end
end

% call scale.m, which is a utility function to linearly scale all elements
% of a matrix to within a certain range: this ensures that the different
% images have roughly the same range of pixel intensities (useful since
% we are only using a single color map to display *all* of them at once)
 y = scale(dvector,-inf,inf,1,256);

% now call reform.m, which is a utility function to reshape a set of images
% stored as vectors, into a large image "mosaic" suitable for display
C = reform(y,ny,nx,bdr,256);

% display the mosaic, first flipping it and rotating the elements
% so that the first image ends up in the top right corner 
D = flipud(rot90(C));
dispimg(D);
axis('off');