<< Chapter < Page | Chapter >> Page > |
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%The following three functions are about the functionalities of
%the 3 buttons of our interface.
%Button 1 let the user to choose the input file.
%Then, it change the input file to gray picture for further
%use.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im;
%get the path of the file, chosen by user
[filename,pathname]=uigetfile({'.bmp'},'choose a file');
str=[pathname,filename];
%read it
im=imread(str);
%change this picture to gray and show it to user in specific
%frame.
im=rgb2gray(im);
axes(handles.axes1);
imshow(im);
%
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im;
%get pictures in our library, change them to gray and store
%them to imgdata
imgdata=[];
for i=1:2
for j=1:5
a=imread(strcat('C:\NewLib\P',num2str(i),'\',num2str(j),'.bmp'));
%a=rgb2gray(a);
%subplot(ceil(sqrt(5)),ceil(sqrt(5)),j)
%imshow(a)
%if i==2
% title('Training set','fontsize',18)
%end
%drawnow;
%standarize the size of each image.
b=a(1:250*360);
b=double(b);
imgdata=[imgdata;b];
%imgdata is a m*n matrix. Each row of it stores an image.
end
end
%get the mean image of images in imgdata
imgdata=imgdata';
imgmean=mean(imgdata,2);
%get minus, a m*n matrix. Each row of it stores
%(each image)-(mean image)
for i=1:10
minus(:,i)=imgdata(:,i)-imgmean;
end
%conve is a m*m matrix
%get coefficients from convex for later use.
convex=minus'*minus;
[coeff,latent,explained]=pcacov(convex');
%get 95% power
i=1;
proportion=0;
while(proportion<95)
proportion=proportion+explained(i);
i=i+1;
end
p=i-1;
i=1;
%make a coordinate system for the traits of ears.
while(i<=p&&latent(i)>0)
base(:,i)=latent(i)^(-1/2)*minus*coeff(:,i);
i=i+1;
end
reference=base'*minus;
%test and show
a=im;
b=a(1:90000);
b=double(b);
b=b';
object=base'*(b-imgmean);
distance=10000;
for k=1:10
temp=norm(object-reference(:,k));
if(distance>temp)
which=k;
distance=temp;
end
end
if (which==10)
title('the person is not in the lib');
end
num1=ceil(which/5);
num2=mod(which,5);
if(num2==0)
num2=5;
end
I=imread(strcat('C:\NewLib\P',num2str(num1),'\',num2str(num2),'.bmp'));
axes(handles.axes2);
switch num1
case 1
imshow(I);
title('this is Gino');
case 2
imshow(I);
title('this is Mark ');
end
%button 3 just close the program.
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(gcf);
Notification Switch
Would you like to follow the 'Elec 301 projects fall 2013' conversation and receive update notifications?