发布时间:2023-02-06 10:30
matlab2013b
步骤一:图片特征提取
这里,关于图片特征的提取,利用garbor变换进行特征提取的。以二维形式存在的人脸图像所包含的数据信息是非常多的,而且,这些数据中还包含了很多与人脸身份并没有多少关系的冗余信息,例如,表情、光线条件等。因此,不能将这些数据直接作为人脸的代表特征来进行识别,也就是必须首先进行特征提取。特征提取的定义为:当原始特征的数量很大,或者说样本是处于一个高维空间中的向量时,通过映射(或变换)的方法用低维空间来表示。如上所述,由于人脸的维数在通常情况下很高,特征提取的成败就对整个识别阶段的效果有决定性的影响。甚至可以这样认为:在某种意义上,人脸识别过程的成败就决定于特征提取的好坏,因此,如何有效的进行特征提取就成为人脸识别科研人员不得不面对的关键性问题。鉴于特征提取的重要性,也有人将它独立作为整个人脸识别过程中的一个阶段。这里,其主要操作时提取特征,并将特征结果向量化,使二维的特征矩阵变为一维的特征向量,从而方便操作。
Face图片:
Noface图片:
这里,我们使用的特征参数公式为:
最后将得到特征图像,然后将其变为一维的向量:
首先,这里面的数据gabor特征数据,具体的理论要看这次提供给你的文献(之前没有给你)
里面有四个论文,其主要的思想是这样的:
首先要了解二维的gabor函数:
这里的feature就是根据gabor函数得到的特征参数组。
这个参数是用来在提取特征的时候,参与运算的。
步骤二:训练
这里,我们主要通过支持向量机,对特种数据进行训练,其主要的理论如下所示:
SVM是20世纪90年代由Vapnik等人提出的,来源于统计学习理论的一种新的数据分类技术。其主要思想就是通过一个非线性变换将原始的数据变换到一个高维的特征空间,并在新的空间实现最优分类。
上述的最优分类函数其最终的分类判别函数以及它的求解过程只涉及样本之间的内积运算。可见,要解决一个特征空间中的最优线性分类问题,只需知道这个空间的内积运算即可。
SVM本身是用于分类的,并不具有比对的功能,本系统为了保证在较高的正确通过率的基础上仍然具有较高的正确拒识率,提出了基于SVM的人脸比对方法。它是在第一步基于个性特征模板的人脸比对结果为“拒绝”的基础上进行的第二层验证。
SVM的主要思想可以概括为两点:
(1) 它是针对线性可分情况进行分析,对于线性不可分的情况,通过使用非线性映射算法将低维输入空间线性不可分的样本转化为高维特征空间使其线性可分,从而 使得高维特征空间采用线性算法对样本的非线性特征进行线性分析成为可能。
(2) 它基于结构风险最小化理论之上在特征空间中建构最优分割超平面,使得学习器得到全局最优化,并且在整个样本空间的期望风险以某个概率满足一定上界。
本文给出 “相似性” 的度量方法来构造 SVM分类器。所谓“相似性” , 是指两幅人脸图像在特征脸空间中值之差,如果各分量都保持在一个较小范围内, 有理由相信这是同一个人脸。
选定集合C={},其中n为人数,和分别为第i个人不同的图像,在特征空间中的值,将其按照如下方案分:,,可以看出正是 “相似” 的人脸, 共有n 个; 而全部都是“非相似”人脸,共有 n* ( n- 1)个,因此,组成如下n*n个训练样本集: 。
现假设在数据库共有 m个已知人脸图像, 基于上述SVM的设计原理, 构造如下的 m个函数( 注意这些函数没有取符号sgn) :
function varargout = main(varargin)
% MAIN MATLAB code for main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_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 main
% Last Modified by GUIDE v2.5 16-Sep-2011 23:09:23
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_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 main is made visible.
function main_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 main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_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)
func_image_features();
warning off;
% --- 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)
load mat\Lib_pic.mat
net = func_trains(PICS);
warning off;
% --- 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)
global I;
global I2;
global Nums;
axes(handles.axes1);
[filename,pathname]=uigetfile({'*.*','All Files(*.*)';},'选择文件');
if isequal([filename,pathname],[0,0])
return
else
pic = fullfile(pathname,filename);
I = imread(pic);
imshow(I,'notruesize');
end
if isrgb(I)
I2 = rgb2gray(I);
else
I2 = imresize(I);
end
axes(handles.axes2);
imshow(I2,'notruesize');
warning off;
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I;
global I2;
global Nums;
global images_facefind
load mat\Network.mat;
Nums2 = str2num(get(handles.edit2,'string'));
images_facefind = func_facefind(net,I2,Nums2);
axes(handles.axes2);
imshow(images_facefind,'notruesize');
warning off;
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
clear;
close all;
warning off;
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
整个算法的测试效果如下所示:
A10-16