% isaac2mat.m : loads ISAAC images saves it to MAT-file.
%
% The ISAAC images contains a numeral '0'..'9' and symbols
% 'm' and '.' which were captured from a video recorder.
% The captured symbols were used for video-frame annotation.
%
% The images are normalized to specified size (img_size) and
% processed by the histogram equalization.
%
% The output is the file 'isaac.mat' which containes:
%   X [dim x num_data] Images represented as column vectors.
%    dim depends on the used image size.
%   y [1 x num_data] Labels:
%    1 ... number '1'
%    2 ... number '2'
%      ... 
%    9 ... number '9'
%   10 ... number '0'
%   11 ... symbol 'm'
%   12 ... symbol '.'
%
% Modifications:
% 25-may-2004, Vojtech Franc

img_size = [10,10];

% contains class names
class_name=cell(12,1); 
for i=1:9, class_name{i} = sprintf('digit %d', i);end
class_name{10} = 'digit 0'; 
class_names{11} = 'symbol m';
class_names{12} = 'symbol .';

X = [];
y = [];
label = 0;
for directory=['c0';'c1';'c2';'c3';'c4';'c5';'c6';'c7';'c8';'c9';'cm';'ct']';
  
  label = label+1;
  
  fprintf('dir: %s, ',directory );
  
  apath = sprintf('labeled/%s/', directory );
  adir = dir(apath);
  
  fprintf(1,'num of images %d\n', size(adir,1));
  
  for i=1:size(adir,1),
    if adir(i).isdir == 0,
      
      fprintf(1,'.');
      
      img = im2double(imread(sprintf('%s%s',apath,adir(i).name), 'bmp'));
      img = histeq(img);
     
      img = imresize(img,img_size,'bilinear');
      img = histeq(img);

      X = [X, img(:)];
      y = [y, label];
      
    end
  end

  fprintf(1,'\n');
end

save isaac X y class_name;
