% Randy Dimmett
% Semester Project
% Readline reads in a line of text in .BMP format
%  and then converts it to text.

[fname,pname] = uigetfile('*.bmp','Select a BITMAP file');
addpath(pname);
Img1 = imread(fname);
BW = im2bw(Img1,.7);

% Prepare input:
[IRows,ICols]=size(BW);
imshow(BW)
while(IRows<MaxRows)
   BW=[BW;ones(1,ICols)];
   IRows=IRows+1;
end
Colsctr=0;
disp('Input gathered.');

% Processing input:
fid = fopen('projectresult.m','w');
outtext='';
start=1;
while((Colsctr+MaxCols-1)<ICols)
      testchar=double(BW(start:BWLength+start-1));
      testout=Wnet*testchar';
      fprintf(fid,'%d',hardlims(testout));

      %testout=sim(net,testchar');
      
      testout=round(testout*27);
      charset='ABCDEFGHIJKLMNOPQRSTUVWXYZ ';
      %charset=' ILTMNYVJUWFEHBKXAZSCOQDPRG';
      if(testout>27 | testout<1)
         charout='?';
      else
        charout=charset(testout);
      end
            Colsctr=Colsctr+MaxCols;
      outtext=[ outtext charout];
      start=start+BWLength;
   end
   fclose(fid);
   
disp('Input processed.');
disp(outtext);