function CI = firstpass(I)
%FIRSTPASS First pass segmentation and classification of postal images.
%   CI = FIRSTPASS(I) performs the first pass classification of I into the 
%   categories: picture, text, background, or undetermined.  This classification 
%   is stored in CI(:,:,2) as follows: 
%
%   1 = picture
%   2 = text
%   3 = background
%   4 = undetermined
%
%   CI(:,:,3) stores the mean value of the block, CI(:,:,4) stores the standard
%   deviation of the block, and CI(:,:,[5,6]) store the bi-intensity values.  
%
%   I specifies the matrix of pixel values of a grayscale image, such as the matrix
%   obtained by IMREAD.  I must have dimensions that are integer multiples of 64x64.  
%
%   See also POSTALSEG, CLASSIFY64, STEP12, L_CLASSIFIER, IMREAD

%   Author(s): K. R. Varshney
%   School of Electrical and Computer Engineering, Cornell University
%   $Date: 2002/08/15 $

% classify all image blocks and fill out CI matrix
[SR,SC] = size(I);
A = 1;
for i=1:64:SR
    B = 1;
    for j=1:64:SC
       % get image block
       block = I([i:i+63],[j:j+63]);
       
       % get first pass classification, mean, and standard deviation
       [CI(A,B,2) CI(A,B,3) CI(A,B,4)] = classify64(block);

       % get bi-intensity values
       [CI(A,B,5),CI(A,B,6)] = bivalue2(block);
       
       B = B + 1;
   end
   A = A + 1;
end

%figure(2);
%imagesc(CI(:,:,2));
%axis image;  

