Info
This question is closed. Reopen it to edit or answer.
what i missing???i cnt find the error..plz help
    1 view (last 30 days)
  
       Show older comments
    
global cropyalefaces;                        %trained face database loaded in RAM
cropyalefaces = [];
M = zeros(1,11);                            %no. of images per person stored in DB
N = zeros(1,15);                            %no. of persons in DB
person = M:N;                               % total no. of persons stored in DB
[~,pathname] = uigetfile('*.gif*','Select any file from DB');
tic;                                        %start counting time to estimate how long the training takes
file = 'C:\Users\admin\Desktop\m.tech\dataset\yalefaces\cropyalefaces\Training set.gif';
[name,ext] = fileparts(file);
%finding the extension of the selected file
%face data base will have the same file extension
%finding directories (=persons) in the DB
op = pwd;                                   % store old path
cd(pathname);                               %filepath contains the paths of the clicked file in the face DB
p2 = pwd;                                   %root of the face DB(current folder)
cd(op);                                     %restore the original path
d = dir(p2);                                %take directory of the face DB to know the persons in the DB
[s, ~] = size(d);                           %ize(d) returns the vector [1 1]. Scalars are regarded as a 1-by-1 arrays
j = 1;                                      %j counts the no of persons (= no folders at this level)
for i = 3:s;                                %1st 2 folders are . & .. i.e. current & parent directory
 if( d(i).isdir == 1 )
name = d(i).name;
person(j).name = name;
l = size( name );
person(j).name_length = l( 2 );
name1 = strcat( p2, '\' );
name1 = strcat( name1, name );
name1 = strcat( name1, '\' );
person(j).path = name1;
j = j + 1;
end
end
persons = j-1;
 disp( 'Scanned face cropyalefaces' );
  fdb = [];                           %total no of faces in DB = sum of all the faces of all the persons
   nof = 0;                           %nof = no of columns in fdb after reading the whole face DB
   for i = 1:persons                  %no of persons in the DB
       p2 = [ person(i).path ext ];
       d = dir( p2 );                  %d = n by 1 struct; n = no of faces
       faces = size( d );              %faces = no of faces of ith person in DB
     for j = 1:faces
       p2 = [ person(i).path d(j).name ];
       im = imread( p2 );
       s = size(im);
       l = length( s );
       if( l == 3 )                        %3=>colour picture
           for  x= 1:s(1,1)                % along x axis of the image
               for y = 1:s(1,2)            % along y axis of the image
                   c = zeros(double(im(x,y,1))+double(im(x,y,2))+double(im(x,y,3)))/3;
               end                        % c = colour intensity at x,y
           end
       else
           c = im;
       end
       double(( c(:)));
       person(i).fd{j} = zeros(t);
       fdb = zeros(fdb,t);
       nof = nof + 1;
     end
     person(i).faces = faces;                                          %faces = no of faces of ith person in DB
   end
   dfdb = [];
   avg_face = mean(fdb,2);
   for i = 1:nof
       dfdb = double( dfdb ( fdb( :, i:i ) ) - avg_face );        % dfdb = [ dfdb double(fdb(:,i:i))-average_face ]; 
   end
     %clear fdb;
     dfdb = dfdb / sqrt( nof );
      %actual correlation matrix = cm = dfdb * dfdb' -> very big matrix
      %calculate dfdb' * dfdb = reduced cm -> much smaller matrix
      %reduced cm = rcm -> nof by nof matrix
      rcm = dfdb' * dfdb;                                   %rcm = reduced correlation matrix
      [rvector, rvalue] = eig( rcm );                       %eigen vector & eigen value of rcm
      %clear rcm;
      disp( 'Calculated Eigen Vectors & Eigen Values of Reduced CM' );
      %normalise eigen vectors of rcm
      for i = 1:persons
          t1 = rvector( :, i );
          s1 = sqrt( sum( t1.^2 ) );
          rvector( :, i ) = rvector( :, i )./s1;
      end
      %calculate eigen vector & eigen value of cm = evector & evalue
      evector = dfdb * rvector;
      evalue = diag( rvalue );
      %clear rvector rvalue
      disp( 'Calculated Eigen Vectors & Eigen Values of CM' );
      [sorted_evalue, index] = sort( evalue );            %sorted in acending order
      sorted_evalue = flipud( sorted_evalue );            %rearranged in decending order
      index = flipud( index );                            %rearranged corresponding indies also
      %Now rearrange eigenvectors in the order of rearranged eigen values
      evector( :, 1:nof ) = evector ( :, index );
      smallest_evalue = (1/100) * sorted_evalue(0);            % to obtain the effective eigen values
      for i = 1:nof
          if (sorted_evalue(i) < smallest_evalue )
              break;
          end
      end
      index = i+1;
      %keep only as many eigen vectors as obtained by above cutoff criterion
      evector = evector( :, 1:index );
      %normalise eigen vectors of cm
      for i = 1:index
      t1 = evector( :, i );
      s1 = sqrt( sum( t1.^2 ) );
      evector( :, i ) = evector( :, i )./s1;
      end
0 Comments
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!