Advertisement
Guest User

Untitled

a guest
May 5th, 2019
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.78 KB | None | 0 0
  1. function [m A eigenfaces pr_img] = eigenface_core(database_path)
  2.   c = 1;
  3.   d = 1;
  4.   for i = 1:10
  5.     path = strcat(database_path,'/');
  6.     number = num2str(i);
  7.     path = strcat(path, number);
  8.     path = strcat(path,'.jpg');
  9.     matrix = double(rgb2gray(imread(path)));
  10.     [a b] = size(matrix);
  11.     for k = 1:a
  12.       for l = 1:b
  13.         T(c,d) = matrix(k,l);
  14.         c++;
  15.       endfor
  16.     endfor
  17.     d++;
  18.     c = 1;
  19.   endfor
  20.   [e f] = size(T);
  21.   for i = 1:e
  22.     m(i) = sum(T(i,:))/f;
  23.     A(i,:) = T(i,:) - m(i);
  24.   endfor
  25.   AUX = A' * A;
  26.   [B C] = eig(AUX);
  27.   diagC = diag(C);
  28.   g = size(diagC);
  29.   h = 1;
  30.   for i = 1:g
  31.     if (diagC(i) > 1)
  32.       V(:,h) = B(:,i);
  33.       h++;
  34.     endif
  35.   endfor
  36.   eigenfaces = A * V;
  37.   pr_img = eigenfaces' * A;
  38. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement