Effacer les filtres
Effacer les filtres

eigenfaces : how to compute weights and how to classify new image

2 vues (au cours des 30 derniers jours)
michael scheinfeild
michael scheinfeild le 9 Mar 2014
hello i want to classify images use eigen faces i transposed the images of train set to eiganface but now i have issue of weights computation and classifiying new image
%%----------------------- % here the issue i am not sure % 1 computing the weights Image = sum(weights* eigenface) ? % 2 new image classification process ?**
//=================
% i have M=4 images N*N N=50
[ st.data{1} st.data{2} ; st.data{3} st.data{4} ];
% average image
for k=1:M
st.data{k} = im2single(st.data{k});
avImg =avImg + (1/M)*st.data{k};
end
%%normalize (remove mean)
for k=1:M
st.dataAvg{k} = st.data{k} -avImg;
end
%%generate A = [ img1(:) img2(:) ... imgM(:) ];
A = zeros(N*N,M);% (N*N)*M 2500*4
for k=1:M
A(:,k) = st.dataAvg{k}(:);
end
% covariance matrix small dimension (transposed)
C = A'*A;
%%eigen vectros in small dimension
[ Veigvec,Deigval ] = eig(C);% v 4*4 e 4*4 only diagonal 4 eigen values
% eigan face in large dimension A*veigvec is eigen vector of Clarge
Vlarge = A*Veigvec;% 2500*4*4*4 =2500 *4
% reshape to eigen face
eigenfaces=[];
for k=1:M
c = Vlarge(:,k);
eigenfaces{k} = reshape(c,N,N);
end
x=diag(Deigval);
[xc,xci]=sort(x,'descend');% largest eigenval
* **%%-----------------------
% here the issue i am not sure
% 1 computing the weights Image = sum(weights* eigenface) ?
% 2 new image classification process ?** *
%%weights
for mi=1:M % image number
for k=1:2 % eigen face for coeff number
wi(mi,k) = sum(A(:,mi).* eigenfaces{xci(k)}(:)) ;
end
end
%%classify new img mic
testFaceMic = imread('C:\Users\michaels.DSI\Desktop\faces\class\mic3.jpg','jpg');
testFaceMic =rgb2gray(testFaceMic);
testFaceMic = imresize(testFaceMic,[N N]);
testFaceMic = im2single(testFaceMic);
Aface = testFaceMic(:)-avImg(:);
w1face = sum(Aface.* eigenfaces{xci(1)}(:)) ;
w2face = sum(Aface.* eigenfaces{xci(2)}(:)) ;

Réponses (0)

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by