1、function varargout = FR_Processed_histogram(varargin)%这种算法是基于直方图处理的方法%The histogram of image is calculated and then bin formation is done on the%basis of mean of successive graylevels frequencies. The training is done on odd images of 40 subjects (200 images out of 400 images) %The results of the im
2、plemented algorithm is 99.75 (recognition fails on image number 4 of subject 17)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_Callba
3、ck, );if nargin end1if nargoutvarargout1:nargout = gui_mainfcn(gui_State, varargin:);elsegui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT%-% - Executes just before FR_Processed_histogram is made visible.function FR_Processed_histogram_OpeningFcn(hObject, eventdata, handle
4、s, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to FR_Processed_histogram (see VARARGIN)% Choose def
5、ault command line output for FR_Processed_histogramhandles.output = hObject;2% Update handles structureguidata(hObject, handles);% UIWAIT makes FR_Processed_histogram wait for user response (see UIRESUME)% uiwait(handles.figure1);global total_sub train_img sub_img max_hist_level bin_num form_bin_num
6、;total_sub = 40;train_img = 200;sub_img = 10;max_hist_level = 256;bin_num = 9;form_bin_num = 29;%-% - Outputs from this function are returned to the command line.function varargout = FR_Processed_histogram_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see V
7、ARARGOUT);3% 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 structurevarargout1 = handles.output;%-% - Executes on button press in train_button. funct
8、ion train_button_Callback(hObject, eventdata, handles)% hObject handle to train_button (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global train_processed_bin;global total_sub train_img sub_img max_hist_level
9、bin_num form_bin_num;train_processed_bin(form_bin_num,train_img) = 0;K = 1;4train_hist_img = zeros(max_hist_level, train_img);for Z=1:1:total_sub for X=1:2:sub_img %train on odd number of images of each subjectI = imread( strcat(ORLS,int2str(Z),int2str(X),.bmp) ); rows cols = size(I);for i=1:1:rowsf
10、or j=1:1:colsif( 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; endend end K = K + 1; end 5end r c = size(train_hist_img);sum = 0;for i=1:1:cK = 1;for j=1:1:r if( (mod(j,bin_num) = 0 )sum = sum + t
11、rain_hist_img(j,i); train_processed_bin(K,i) = sum/bin_num;K = K + 1;sum = 0;elsesum = sum + train_hist_img(j,i); endendtrain_processed_bin(K,i) = sum/bin_num;enddisplay (Training Done)save train train_processed_bin;6%-% - Executes on button press in Testing_button. function Testing_button_Callback(
12、hObject, eventdata, handles)% hObject handle to Testing_button (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global train_img max_hist_level bin_num form_bin_num;global train_processed_bin;global filename pathn
13、ame Iload traintest_hist_img(max_hist_level) = 0;test_processed_bin(form_bin_num) = 0;rows cols = size(I);for i=1:1:rowsfor j=1:1:colsif( I(i,j) = 0 )test_hist_img(max_hist_level) = 7test_hist_img(max_hist_level) + 1; elsetest_hist_img(I(i,j) = test_hist_img(I(i,j) + 1; endend end r c = size(test_hi
14、st_img);sum = 0;K = 1;for j=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;elsesum = sum + test_hist_img(j); endend8test_processed_bin(K) = sum/bin_num;sum = 0;K = 1;for y=1:1:train_imgfor z=1:1:form_bin_num sum = sum + abs( test_pr
15、ocessed_bin(z) - train_processed_bin(z,y) ); end img_bin_hist_sum(K,1) = sum;sum = 0;K = K + 1;endtemp M = 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;9subjectindex=
16、str2num(pathname(getString_start:getString_end);if (subjectindex = M)axes (handles.axes3)%image no: 5 is shown for visualization purposeimshow(imread(STRCAT(ORLS,num2str(M),5.bmp) msgbox ( Correctly Recognized);elsedisplay ( Error= Testing Image of Subject num2str(subjectindex) matches with the imag
17、e of subject num2str(M)axes (handles.axes3)%image no: 5 is shown for visualization purposeimshow(imread(STRCAT(ORLS,num2str(M),5.bmp) msgbox ( Incorrectly Recognized);enddisplay(Testing Done)%-function box_Callback(hObject, eventdata, handles)% hObject handle to box (see GCBO)% eventdata reserved -
18、to be defined in a future version of 10MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,String) returns contents of box as text% str2double(get(hObject,String) returns contents of box as a double%-% - Executes during object creation, after setting all properties
19、.function box_CreateFcn(hObject, eventdata, handles)% hObject handle to box (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC a
20、nd COMPUTER.if ispc end11%-% - Executes on button press in Input_Image_button.function Input_Image_button_Callback(hObject, eventdata, handles)% hObject handle to Input_Image_button (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user
21、data (see GUIDATA)global filename pathname Ifilename, pathname = uigetfile(*.bmp, Test Image);axes(handles.axes1)imgpath=STRCAT(pathname,filename);I = imread(imgpath);imshow(I)%-% - Executes during object creation, after setting all properties.function axes3_CreateFcn(hObject, eventdata, handles)% hObject handle to axes3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns 12called% Hint: place code in OpeningFcn to populate axes3 %Programmed by Usman Qayyum