www.gusucode.com > 完整的人连表情识别系统源代码(采用局域二值模式LBP识别) > code9/untitled.m
function varargout = untitled(varargin) % UNTITLED M-file for untitled.fig % UNTITLED, by itself, creates a new UNTITLED or raises the existing % singleton*. % % H = UNTITLED returns the handle to a new UNTITLED or the handle to % the existing singleton*. % % UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in UNTITLED.M with the given input arguments. % % UNTITLED('Property','Value',...) creates a new UNTITLED or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before untitled_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to untitled_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help untitled % Last Modified by GUIDE v2.5 26-May-2009 09:41:48 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled_OpeningFcn, ... 'gui_OutputFcn', @untitled_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before untitled is made visible. function untitled_OpeningFcn(hObject, eventdata, handles, 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 untitled (see VARARGIN) % Choose default command line output for untitled handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes untitled wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = untitled_OutputFcn(hObject, eventdata, handles) % 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; % --- 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 pathname; % [imagefile , pathname]= uigetfile('*.png;*.jpg;*bmp','Please select an image file '); % if imagefile ~= 0 % filename=[pathname imagefile]; % [X,map]=imread(filename); % I=X; % end; % axes(handles.axes1) % imshow(I) % title('原始图像'); % hold on % [m,n]=size(I) % % [x,y] = ginput(4) ; % plot(x,y,'rx') % hold off % % center1=[(x(1)+x(2))/2,(y(1)+y(2))/2]; % center2=[(x(3)+x(4))/2,(y(3)+y(4))/2]; % % % d=80; % % d1=(x(2)-x(1)) % Angle1= atan((y(2)-y(1))/(x(2)-x(1))); % Angle=Angle1*180/pi; % I=imrotate(I,Angle); % h1=abs(fix(n*sin(Angle1)))+1 % w1=abs(fix(m*sin(Angle1)))+1 % R=I(h1:m-h1,w1:n-w1); % axes(handles.axes2) % imshow(R); % title('归一化图像'); % R=imresize(R,[102 82]); % --- 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) train=[]; datamumber=[]; for classnumber=1:2 [imagefile , pathname]= uigetfile('*.png;*.jpg;*bmp;*tiff','Please select an image file '); % if imagefile ~= 0 % filename=[pathname imagefile]; % [X,map]=imread(filename); % I=X; % end; path=[pathname,'*.bmp'] list=dir(path); nfiles=length(list); % addpath 'G:\cohn-kanade\testAU1AU2'; % nfiles1=min(10,nfiles) % n1=nfiles1; datamumber=[datamumber,nfiles] for i=1:nfiles filename1=[pathname ,list(i).name]; I=imread(filename1); axes(handles.axes1); imshow(I); title('原始图像'); hold on [m,n]=size(I); [x,y] = ginput(4) ; plot(x,y,'rx') hold off center1=[(x(1)+x(2))/2,(y(1)+y(2))/2]; center2=[(x(3)+x(4))/2,(y(3)+y(4))/2]; Angle1= atan((y(2)-y(1))/(x(2)-x(1))); Angle=Angle1*180/pi; I=imrotate(I,Angle); h1=abs(fix(n*sin(Angle1)))+1 w1=abs(fix(m*sin(Angle1)))+1 R=I(h1:m-h1,w1:n-w1); axes(handles.axes2) imshow(R); title('归一化图像'); R=imresize(R,[102 82]); AU=LBP(R); %feature=abs(AU1-NE); train=[train,AU']; end end zhongxin=[mean(train(:,1:datamumber(1)),2),mean(train(:,datamumber(1)+1:datamumber(2)),2)] save zhongxin; % --- 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) [imagefile , pathname]= uigetfile('*.png;*.jpg;*bmp;*tiff','Please select an image file '); if imagefile ~= 0 filename=[pathname imagefile]; [X,map]=imread(filename); I=X; end; axes(handles.axes1) imshow(I) title('原始图像'); hold on [m,n]=size(I) [x,y] = ginput(4) ; plot(x,y,'rx') hold off center1=[(x(1)+x(2))/2,(y(1)+y(2))/2]; center2=[(x(3)+x(4))/2,(y(3)+y(4))/2]; Angle1= atan((y(2)-y(1))/(x(2)-x(1))); Angle=Angle1*180/pi; I=imrotate(I,Angle); h1=abs(fix(n*sin(Angle1)))+1 w1=abs(fix(m*sin(Angle1)))+1 R=I(h1:m-h1,w1:n-w1); axes(handles.axes2) imshow(R); title('归一化图像'); R=imresize(R,[102 82]); AU1=LBP(R); load zhongxin distance=[]; result=[] COM=size(zhongxin,2); for i3=1:COM d=norm(zhongxin(:,i3)-AU1') distance=[distance,d]; end [Y,I]=sort(distance); result=I(1); if result==1 message='识别结果为第一类'; msgbox(message) end if result==2 message='识别结果为第二类'; msgbox(message) end