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

    function B = reform(A, dr, dc, bs, bv, ncc)
%
% REFORM: B = reform(A, dr, dc, bs, bv, ncc);
%
% This program creates a large mosaic image from the rows of matrix A
%
% note: "chip" below refers to an image within the large mosaic. 
% 
% Convert each row of A into a dr X dc chip within a mosaic image B.
% Arguments:
%   A   - input matrix with chips as rows
%   dr  - number of rows in a chip
%   dc  - number of cols in a chip
%   bs  - (optional) size of border between chips
%   bv  - (optional) value given to pixels in borders
%   ncc - (optional) number of chips per row in B
% 

[ar, ac] = size(A);

if (nargin < 6)
  ncc = ceil(sqrt(ar));  % Number of chip columns (i.e., nchips per row)
end
if (nargin < 5) 
  bv = 0;
end
if (nargin < 4)
  bs = 3;
end

ncr = ceil(ar/ncc); % Number of chip rows
%[ncr, ncc];
%
bdr = dr + bs;
bdc = dc + bs;
%
% Preallocate B
B = bv .* ones(ncr * bdr, ncc * bdc - bs);
%
% Convert each row of A into a chip in B
for i = 1 : ar
  r0 = 1 + fix((i-1)/ncc)  * bdr;
  c0 = 1 + rem((i-1), ncc) * bdc;
  B(r0:r0+dr-1, c0:c0+dc-1) = (reshape(A(i,:), dc, dr))';
end