基于matlab的人脸识别源代码.docx

上传人:b****3 文档编号:24763545 上传时间:2023-06-01 格式:DOCX 页数:8 大小:16.39KB
下载 相关 举报
基于matlab的人脸识别源代码.docx_第1页
第1页 / 共8页
基于matlab的人脸识别源代码.docx_第2页
第2页 / 共8页
基于matlab的人脸识别源代码.docx_第3页
第3页 / 共8页
基于matlab的人脸识别源代码.docx_第4页
第4页 / 共8页
基于matlab的人脸识别源代码.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

基于matlab的人脸识别源代码.docx

《基于matlab的人脸识别源代码.docx》由会员分享,可在线阅读,更多相关《基于matlab的人脸识别源代码.docx(8页珍藏版)》请在冰豆网上搜索。

基于matlab的人脸识别源代码.docx

基于matlab的人脸识别源代码

functionvarargout=FR_Processed_histogram(varargin)%这种算法是基于直方图处理的方法

%Thehistogramofimageiscalculatedandthenbinformationisdoneonthe

%basisofmeanofsuccessivegraylevelsfrequencies.Thetrainingisdoneonoddimagesof40subjects(200imagesoutof400images)

%Theresultsoftheimplementedalgorithmis99.75(recognitionfailsonimagenumber4ofsubject17)

gui_Singleton=1;

gui_State=struct('gui_Name',mfilename,...

'gui_Singleton',gui_Singleton,...'gui_OpeningFcn',@FR_Processed_histogram_OpeningFcn.,..

'gui_OutputFcn',@FR_Processed_histogram_OutputFcn.,..

'gui_LayoutFcn',[],...'gui_Callback',[]);

ifnargin&&ischar(varargin{1})gui_State.gui_Callback=str2func(varargin{1});

end

ifnargout

[varargout{1:

nargout}]=gui_mainfcn(gui_State,varargin{:

});

else

gui_mainfcn(gui_State,varargin{:

});

end

%Endinitializationcode-DONOTEDIT

%

%---ExecutesjustbeforeFR_Processed_histogramismadevisible.functionFR_Processed_histogram_OpeningFcn(hObjecte,ventdata,handles,varargin)

%Thisfunctionhasnooutputargs,seeOutputFcn.

%hObjecthandletofigure

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%varargincommandlineargumentstoFR_Processed_histogram(seeVARARGIN)

%Choosedefaultcommandlineoutputfor

FR_Processed_histogram

handles.output=hObject;

%Updatehandlesstructureguidata(hObject,handles);

%UIWAITmakesFR_Processed_histogramwaitforuserresponse(seeUIRESUME)

%uiwait(handles.figure1);

globaltotal_subtrain_imgsub_imgmax_hist_levelbin_numform_bin_num;

total_sub=40;

train_img=200;

sub_img=10;

max_hist_level=256;

bin_num=9;

form_bin_num=29;

%

%---Outputsfromthisfunctionarereturnedtothecommandline.

functionvarargout=FR_Processed_histogram_OutputFcn(hObject,eventdata,handles)

%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);

%hObjecthandletofigure

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%Getdefaultcommandlineoutputfromhandlesstructurevarargout{1}=handles.output;

%

%---Executesonbuttonpressintrain_button.

functiontrain_button_Callback(hObject,eventdata,handles)

%hObjecthandletotrain_button(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

globaltrain_processed_bin;

globaltotal_subtrain_imgsub_imgmax_hist_levelbin_numform_bin_num;

train_processed_bin(form_bin_num,train_img)=0;

K=1;

train_hist_img=zeros(max_hist_level,train_img);

forZ=1:

1:

total_sub

forX=1:

2:

sub_img

%%%trainonoddnumberofimagesof

eachsubject

I=imread(strcat('ORL\S',int2str(Z),'\',int2str(X),'.bmp'));[rowscols]=size(I);

fori=1:

1:

rows

forj=1:

1:

cols

if(I(i,j)==0)train_hist_img(max_hist_level,K)train_hist_img(max_hist_level,K)+1;

elsetrain_hist_img(I(i,j),K)=train_hist_img(I(i,j),K)+1;

end

end

end

K=K+1;

end

end

[rc]=size(train_hist_img);

sum=0;

fori=1:

1:

c

K=1;

forj=1:

1:

r

if((mod(j,bin_num))==0)

sum=sum+train_hist_img(j,i);train_processed_bin(K,i)=sum/bin_num;K=K+1;

sum=0;

else

sum=sum+train_hist_img(j,i);

end

end

train_processed_bin(K,i)=sum/bin_num;

end

display('TrainingDone')save'train'train_processed_bin;

%---ExecutesonbuttonpressinTesting_button.

functionTesting_button_Callback(hObject,eventdata,handles)

%hObjecthandletoTesting_button(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

globaltrain_imgmax_hist_levelbin_numform_bin_num;

globaltrain_processed_bin;

globalfilenamepathnameI

load'train'

test_hist_img(max_hist_level)=0;test_processed_bin(form_bin_num)=0;

[rowscols]=size(I);

fori=1:

1:

rows

forj=1:

1:

cols

if(I(i,j)==0)

test_hist_img(max_hist_level)

test_hist_img(max_hist_level)+1;

else

test_hist_img(I(i,j))=test_hist_img(I(i,j))+1;

end

end

end

[rc]=size(test_hist_img);sum=0;

K=1;

forj=1:

1:

c

if((mod(j,bin_num))==0)

sum=sum+test_hist_img(j);test_processed_bin(K)=sum/bin_num;

K=K+1;

sum=0;

else

sum=sum+test_hist_img(j);

end

end

test_processed_bin(K)=sum/bin_num;

sum=0;

K=1;

fory=1:

1:

train_img

forz=1:

1:

form_bin_num

sum=sum+abs(test_processed_bin(z)-train_processed_bin(z,y));

end

img_bin_hist_sum(K,1)=sum;

sum=0;

K=K+1;

end

[tempM]=min(img_bin_hist_sum);

M=ceil(M/5);

getString_start=strfind(pathname',S');getString_start=getString_start(end)+1;getString_end=strfind(pathname',\');getString_end=getString_end(end)-1;

subjectindex=str2num(pathname(getString_start:

getString_end));

if(subjectindex==M)

axes(handles.axes3)

%imageno:

5isshownforvisualizationpurposeimshow(imread(STRCAT('ORL\S',num2str(M),'\5.bmp')))msgbox('CorrectlyRecognized');

else

display(['Error==>TestingImageofSubject>>'num2str(subjectindex)'matcheswiththeimageofsubject>>'num2str(M)])

axes(handles.axes3)

%imageno:

5isshownforvisualizationpurposeimshow(imread(STRCAT('ORL\S',num2str(M),'\5.bmp')))msgbox('IncorrectlyRecognized');

end

display('TestingDone')

%

functionbox_Callback(hObject,eventdata,handles)

%hObjecthandletobox(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionof

MATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

%Hints:

get(hObject,'String')returnscontentsofboxastext

%str2double(get(hObject,'String'))returnscontentsofboxasadouble

%

%---Executesduringobjectcreation,aftersettingallproperties.functionbox_CreateFcn(hObject,eventdata,handles)

%hObjecthandletobox(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesempty-handlesnotcreateduntilafterallCreateFcns

called

%Hint:

editcontrolsusuallyhaveawhitebackgroundonWindows.

%SeeISPCandCOMPUTER.

ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

%---ExecutesonbuttonpressinInput_Image_button.

functionInput_Image_button_Callback(hObject,eventdata,handles)

%hObjecthandletoInput_Image_button(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesstructurewithhandlesanduserdata(seeGUIDATA)

globalfilenamepathnameI

[filename,pathname]=uigetfile('*.bmp','TestImage');axes(handles.axes1)

imgpath=STRCAT(pathname,filename);

I=imread(imgpath);

imshow(I)

%

%---Executesduringobjectcreation,aftersettingallproperties.

functionaxes3_CreateFcn(hObject,eventdata,handles)

%hObjecthandletoaxes3(seeGCBO)

%eventdatareserved-tobedefinedinafutureversionofMATLAB

%handlesempty-handlesnotcreateduntilafterallCreateFcns

called

%Hint:

placecodeinOpeningFcntopopulateaxes3

%ProgrammedbyUsmanQayyum

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 职业教育 > 中职中专

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1