function disp_digits(data, height, width)
%  This function displays images of characters stored as columns 
%  of the matrix data.X. The output is displayed in a grid 5 x 10.
%
% Input:
%  data.X [dim x :] Input images store as column vectors.
%    The images are assumed to be taken from grid 5x10.
%
% Modified by Xiuwen Liu on Jan 12, 2006
% (c) Statistical Pattern Recognition Toolbox, (C) 1999-2003,
% Written by Vojtech Franc and Vaclav Hlavac,
% <a href="http://www.cvut.cz">Czech Technical University Prague</a>,
% <a href="http://www.feld.cvut.cz">Faculty of Electrical engineering</a>,
% <a href="http://cmp.felk.cvut.cz">Center for Machine Perception</a>

% Modifications:
% 04-jun-2004, VF
% 09-sep-2003, VF
% 12-01-2006, XL
% displays results
%-------------------------------------------------------
clf;
hold on;
colormap(gray(256));
% display recognized numerals
gap = 5;
imgX=zeros([5*height+gap*6 10*width+gap*10])+255;
k=0;
while k < size(data.X,2), 
    for i=1:5,
       for j = 1:10,
          inx = j+(i-1)*10+k;
          if inx <= size(data.X,2),
             img=data.X(:,inx);
             %keyboard
             img=reshape(img,[16 16]);
             img=255*(1-img);
             startRow=(5-i)*height+(5-i+1)*gap;
             startCol=(j-1)*width+(j)*gap;
             imgX((startRow+height-1):(-1):startRow,startCol:(startCol+width-1))=img;
             %keyboard
          else 
              break;
          end
       end
       if inx > size(data.X,2),
           inx = size(data.X,2);
           break;
       end
    end
    image(imgX);
    title([sprintf('Digits %d - %d',k+1, inx)],'FontSize',[16]);
    axis('image');
    axis('off');
    plot( [ 1 1 size(imgX,2) size(imgX,2) 1 ], [ 1 size(imgX,1) size(imgX,1) 1 1 ] );
    for i = 1:9, 
        startP=(i)*width+(i+1)*gap-gap/2;
        plot( [startP startP],[1 size(imgX,1)] ); 
    end
    for i = 1:4, 
        startP = (5-i)*height+(5-i+1)*gap-gap/2;
        plot( [1 size(imgX,2)],[startP startP] ); 
    end
    k=k+50;
    if k < size(data.X,2),
        fprintf(2,'Press any key to display the next 50 digits');
        pause;
        fprintf(2,'\n');
    end
end
%keyboard
return;
% EOF
