when i am trying to run the program i got error in the program at 27 line. please help me to find out the problem and if you have real time face recognition code,send me on my mail id

1 view (last 30 days)
clear all;clc; % INTRODUCTION display('Hi this is face recognition system'); display('Procedure for face recognition is as follows'); display('1.training using 12 faces'); display('2.Find the Principal Component'); display('3. Principal component is used as measure to detect test face'); display('4. Calucalate the distance between the test face and principal component'); display('5.decision : if the distance is below threshold then'); display(' the test face is detected as one of the train face'); display(' else the test face is detected as new face'); %READING INPUT IMAGES face1=imread('D:\photos\project data\a','jpeg'); face2=imread('D:\photos\project data\b','jpeg'); face3=imread('D:\photos\project data\c','jpeg'); face4=imread('D:\photos\project data\d','jpeg'); face5=imread('D:\photos\project data\e','jpeg'); face6=imread('D:\photos\project data\f','jpeg'); face7=imread('D:\photos\project data\g','jpeg'); face8=imread('D:\photos\project data\h','jpeg'); face9=imread('D:\photos\project data\i','jpeg'); face10=imread('D:\photos\project data\j','jpeg'); face11=imread('D:\photos\project data\k','jpeg'); face12=imread('D:\photos\project data\l','jpeg'); %DISPLAY THE ORIGINAL IMAGE subplot(3,4,1);imshow(face1);subplot(3,4,2);imshow(face2);subplot(3,4,3);imshow(face3);subplot(3,4,4);imshow(face4);subplot(3,4,5);imshow(face5);subplot(3,4,6);imshow(face6);subplot(3,4,7);imshow(face7);subplot(3,4,8);imshow(face8);subplot(3,4,9);imshow(face9);subplot(3,4,10);imshow(face10);subplot(3,4,11);imshow(face11);subplot(3,4,12);imshow(face12); Image([face1, face2, face3, face4, face5, face6, face7, face8, face9, face10, face11, face12]) colormap (gray); face1=face1(:,:,1); face2=face2(:,:,1); face3=face3(:,:,1); face4=face4(:,:,1); face5=face5(:,:,1); face6=face6(:,:,1); face7=face7(:,:,1); face8=face8(:,:,1); face9=face9(:,:,1); face10=face10(:,:,1); face11=face11(:,:,1); face12=face12(:,:,1); %TWO DIMENTIONAL WAVELET TRANSFORM OF ORIGINAL IMAGE [cA1,cH1,cV1,cD1]=dwt2(face1,'db6'); [cA2,cH2,cV2,cD2]=dwt2(face2,'db6'); [cA3,cH3,cV3,cD3]=dwt2(face3,'db6'); [cA4,cH4,cV4,cD4]=dwt2(face4,'db6'); [cA5,cH5,cV5,cD5]=dwt2(face5,'db6'); [cA6,cH6,cV6,cD6]=dwt2(face6,'db6'); [cA7,cH7,cV7,cD7]=dwt2(face7,'db6'); [cA8,cH8,cV8,cD8]=dwt2(face8,'db6'); [cA9,cH9,cV9,cD9]=dwt2(face9,'db6'); [cA10,cH10,cV10,cD10]=dwt2(face10,'db6'); [cA11,cH11,cV11,cD11]=dwt2(face11,'db6'); [cA12,cH12,cV12,cD12]=dwt2(face12,'db6'); %DISPLAY THE TWO DIMENTIONAL WAVELET TRANSFORM OF ORIGINAL IMAGE figure; image([cA1, cA2, cA3, cA4, cA5, cA6, cA7, cA8, cA9, cA10, cA11, cA12]); colormap(gray); title ('Approximation coefficient of 12 faces'); %12 IMAGES TO FORM STACK "S" S=cat(3, cA1, cA2, cA3, cA4, cA5, cA6, cA7, cA8, cA9, cA10, cA11, cA12); %STACK OF VECTORS [M,N,n_0]=size(S); MASK=true(M,N); [I,J]=find(MASK); R=[I,J]; Q=M*N; X=reshape(S,Q,n_0); MASK=reshape(MASK,Q,1); %COVARIANCE OF MATRIX 'X' Xtemp=X; [K,n_1]=size(Xtemp); Xtemp=double(Xtemp); if n_1==1 P.Cx=0; P.mx=Xtemp; else m=sum(Xtemp,1)/K; Xtemp= Xtemp-m(ones(K,1),:); P.Cx=( Xtemp'* Xtemp)/(K-1); P.mx=m'; end %COVARIANCE MATRIX AND MEAN display('Covariance Matrix and means of 12 faces'); P.Cx P.mx %PRINCIPAL COMPONENT ANALYSIS n_2=12; %specifies how many PCA vectors are used P.mx=P.mx'; [V,D]=eig(P.Cx); d=diag(D); [d,idx]=sort(d); d=flipud(d); idx=flipud(idx); D=diag(d); V=V(:,idx); P.A=V(:,1:n_2)'; Mx=repmat(P.mx,K,1); P.Y=P.A*(X-Mx)'; P.Y=P.Y'; P.mx=P.mx'; display(P.mx); d=diag(D); P.ems=sum(d(n_2+1:end)); P.Cy=P.A*P.Cx*P.A'; %DISPLAY THE 12 EIGEN FACES OF ORIGINAL IMAGE figure; plot(2,2); subplot(2,2,1); g1=P.Y(:,1); g1=reshape(g1,M,N); imshow(g1,[]); title('1st PRINCIPAL COMPONENT'); subplot(2,2,2); g2=P.Y(:,2); g2=reshape(g2,M,N); imshow(g2,[]); title('2nd PRINCIPAL COMPONENT'); subplot(2,2,3); g3=P.Y(:,3); g3=reshape(g3,M,N); imshow(g3,[]); title('3rd PRINCIPAL COMPONENT'); subplot(2,2,4); g4=P.Y(:,4); g4=reshape(g4,M,N); imshow(g4,[]); title('4th PRINCIPAL COMPONENT'); figure; plot(2,2); subplot(2,2,1); g5=P.Y(:,5); g5=reshape(g5,M,N); imshow(g5,[]); title('5th PRINCIPAL COMPONENT'); subplot(2,2,2); g6=P.Y(:,6); g6=reshape(g6,M,N); imshow(g6,[]); title('6th PRINCIPAL COMPONENT'); subplot(2,2,3); g7=P.Y(:,7); g7=reshape(g7,M,N); imshow(g7,[]); title('7th PRINCIPAL COMPONENT'); subplot(2,2,4); g8=P.Y(:,8); g8=reshape(g8,M,N); imshow(g8,[]); title('8th PRINCIPAL COMPONENT'); figure; plot(2,2); subplot(2,2,1); g9=P.Y(:,9); g9=reshape(g9,M,N); imshow(g9,[]); title('9th PRINCIPAL COMPONENT'); subplot(2,2,2); g10=P.Y(:,10); g10=reshape(g10,M,N); imshow(g10,[]); title('10th PRINCIPAL COMPONENT'); subplot(2,2,3); g11=P.Y(:,11); g11=reshape(g11,M,N); imshow(g11,[]); title('11th PRINCIPAL COMPONENT'); subplot(2,2,4); g12=P.Y(:,12); g12=reshape(g12,M,N); imshow(g12,[]); title('12th PRINCIPAL COMPONENT'); %Eign values( 1st value is more promenent than others and hence principalcomponent) eigen_values = diag(P.Cy); %display('This matrix shows 12eign values in which first value shows principal component'); g1=P.Y(:,1); eig_first_comp=reshape(g1,M,N); %figure; J0=imresize(eig_first_comp,2); %imshow(J0); title('EIGEN FIRST COMPONENT'); %display('Here Threshold fixed is 1.28'); sum1=0; diff1=(cA1-eig_first_comp); for i=1:M for j=1:N temp=diff1(i,j); sum1=sum1+temp; end end %display('Distance calucalated between principal component and 1st face imagein database'); avg1=(sum1/(i+j))*10^-004; %figure; J1=imresize(diff1,2.5); %imshow(J1); %title('difference 1st image in database is considered as test face'); sum2=0; diff2=(cA2-eig_first_comp); for i=1:M for j=1:N sum2=sum2+diff2(i,j); end end %display('Distance calucalated between principal component and 2nd face image in database'); avg2=(sum2/(i+j))*10^-004; %figure; J2=imresize(diff2,2.5); %imshow(J2); %title('difference 2nd image in database is considered as test face'); sum3=0; diff3=(cA3-eig_first_comp); for i=1:M for j=1:N sum3=sum3+diff3(i,j); end end %display('Distance calucalated between principal component and 3rd face image in database'); avg3=(sum3/(i+j))*10^-004; %figure; J3=imresize(diff3,2.5); %imshow(J3); %title('difference 3rd image in database is considered as test face'); sum4=0; diff4=(cA4-eig_first_comp); for i=1:M for j=1:N sum4=sum4+diff4(i,j); end end %display('Distance calucalated between principal component and 3rd face image in database'); avg4=(sum4/(i+j))*10^-004; %figure; J4=imresize(diff3,2.5); %imshow(J4); %title('difference 4th image in database is considered as test face'); sum5=0; diff5=(cA5-eig_first_comp); for i=1:M for j=1:N sum5=sum5+diff5(i,j); end end %display('Distance calucalated between principal component and 3rd face image in database'); avg5=(sum5/(i+j))*10^-004; %figure; J5=imresize(diff5,2.5); %imshow(J5); %title('difference 5th image in database is considered as test face'); sum6=0; diff6=(cA6-eig_first_comp); for i=1:M for j=1:N sum6=sum6+diff6(i,j); end end %display('Distance calucalated between principal component and 3rd face image in database'); avg6=(sum6/(i+j))*10^-004; %figure; J6=imresize(diff6,2.5); %imshow(J6); %title('difference 6th image in database is considered as test face'); sum7=0; diff7=(cA7-eig_first_comp); for i=1:M for j=1:N sum7=sum7+diff7(i,j); end end %display('Distance calucalated between principal component and 3rd face image in database'); avg7=(sum7/(i+j))*10^-004; %figure; J9=imresize(diff9,2.5); %imshow(J9); %title('difference 9th image in database is considered as test face'); sum10=0; diff10=(cA10-eig_first_comp); for i=1:M for j=1:N sum10=sum10+diff10(i,j); end end %display('Distance calucalated between principal component and 3rd face image in database'); avg10=(sum10/(i+j))*10^-004; %figure; J10=imresize(diff10,2.5); %imshow(J10); %title('difference 3rd image in database is considered as test face'); sum11=0; diff11=(cA11-eig_first_comp); for i=1:M for j=1:N sum11=sum11+diff11(i,j); end end %display('Distance calucalated between principal component and 3rd face image in database'); avg11=(sum11/(i+j))*10^-004; %figure; J11=imresize(diff11,2.5); %imshow(J11); %title('difference 3rd image in database is considered as test face'); sum12=0; diff12=(cA12-eig_first_comp); for i=1:M for j=1:N sum12=sum12+diff12(i,j); end end %display('Distance calucalated between principal component and 3rd face image in database'); avg12=(sum12/(i+j))*10^-004; %figure; J12=imresize(diff12,2.5); %imshow(J12); %title('difference 12th image in database is considered as test face'); testsum=0; test=imread('D:\photos\project data\v','jpeg'); test=test(:,:,1); figure; imshow(test); title('TEST FACE FOR DETECTION'); [cAtest,cHtest,cVtest,cDtest]=dwt2(test,'db6'); testdiff=(cAtest-eig_first_comp); for i=1:M for j=1:N testsum=testsum+testdiff(i,j); end end %display('Distance calucalated between principal component and test face'); testavg=(testsum/(i+j))*10^-004; %figure; Jt=imresize(testdiff,2.5); %imshow(Jt); %title('DIFFERENCE-NEW IMAGE IS CONSIDERED AS TEST FACE'); if((testavg==avg1)||(testavg==avg2)||(testavg==avg3)||(testavg==avg4)||(testavg==avg5)||(testavg==avg6)||(testavg==avg7)||(testavg==avg8)||(testavg==avg9)||(testavg==avg10)||(testavg==avg11)||(testavg==avg12)) display('Test face is already in database'); else display('Test face is not in database'); end

Answers (0)

Community Treasure Hunt

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

Start Hunting!