Matlab PCA人脸识别(识别率)【详细解析 源码 GUI界面】

PCA算法是人脸识别中最简单的一种识别算法。

1 PCA
PCA(Principal Component Analysis)是常用的数据分析方法。PCA是通过线性变换,将原始数据变换为一组各维度线性无关的数据表示方法,可用于提取数据的主要特征分量,常用于高维数据的降维。

1.1 降维问题
数据挖掘和机器学习中,数据以向量表示。例如某个淘宝店2012年全年的流量及交易情况可以看成一组记录的集合,其中每一天的数据是一条记录,格式如下:
(日期, 浏览量, 访客数, 下单数, 成交数, 成交金额)
其中"日期"是一个记录标志而非度量值,而数据挖掘关心的大多是度量值,因此如果我们忽略日期这个字段后,我们得到一组记录,每条记录可以被表示为一个五维向量,其中一条样本如下所示:

一般习惯上使用列向量表示一条记录,本文后面也会遵循这个准则。
机器学习的很多算法复杂度和数据的维数有着密切关系,甚至与维数呈指数级关联。这里区区5维的数据,也许无所谓,但是实际机器学习中处理成千上万甚至几十万维的数据也并不罕见,在这种情况下,机器学习的资源消耗是不可接受的,因此就会对数据采取降维的操作。降维就意味着信息的丢失,不过鉴于实际数据本身常常存在相关性,所以在降维时想办法降低信息的损失。
例如上面淘宝店铺的数据,从经验可知,"浏览量"和"访客数"往往具有较强的相关性,而"下单数"和"成交数"也具有较强的相关性。可以直观理解为"当某一天这个店铺的浏览量较高(或较低)时,我们应该很大程度上认为这天的访客数也较高(或较低)"。因此,如果删除浏览量或访客数,最终并不会丢失太多信息,从而降低数据的维度,也就是所谓的降维操作。如果把数据降维用数学来分析讨论,用专业名词表示就是PCA,这是一种具有严格数学基础并且已被广泛采用的降维方法。

1.2 向量与基变换
1.2.1 内积与投影
两个大小相同向量的内积被定义如下:

% applied to the GUI before face_OpeningFcn gets called. An

% unrecognized property name or invalid value makes property application

% stop. All inputs are passed to face_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 face

% Last Modified by GUIDE v2.5 18-Dec-2014 12:02:18

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

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

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @face_OpeningFcn, ...

'gui_OutputFcn', @face_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 face is made visible. function face_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 face (see VARARGIN) % Choose default command line output for face handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes face wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = face_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) % read image to be recognize global im; \[filename, pathname\] = uigetfile({'\*.bmp'},'choose photo'); str = \[pathname, filename\]; im = imread(str); 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 global reference global W global imgmean global col_of_data global pathname global img_path_list % 最小距离法,寻找和待识别图片最为接近的训练图片 for k = 1:col_of_data temp = norm(objectone - reference(:,k)); if(distance\>temp) aimone = k; distance = temp; aimpath = strcat(pathname, '/', img_path_list(aimone).name); axes( handles.axes2 ) imshow(aimpath) end end % 显示测试结果 % aimpath = strcat(pathname, '/', img_path_list(aimone).name); % axes( handles.axes2 ) % imshow(aimpath) % --- Executes on button press in pushbutton3. % 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) ### ******三、参考运行图****** ![](https://i-blog.csdnimg.cn/direct/0eeac4dd4609462caa1b127880ebc072.png)

相关推荐
flyair_China12 分钟前
【云架构】
开发语言·php
Chef_Chen18 分钟前
从0开始学习R语言--Day20-ARIMA与格兰杰因果检验
开发语言·学习·r语言
zh_xuan18 分钟前
c++ std::pair
开发语言·c++
CodeWithMe40 分钟前
【C/C++】EBO空基类优化介绍
开发语言·c++
404.Not Found1 小时前
Day46 Python打卡训练营
开发语言·python
love530love1 小时前
【PyCharm必会基础】正确移除解释器及虚拟环境(以 Poetry 为例 )
开发语言·ide·windows·笔记·python·pycharm
凌辰揽月1 小时前
Web后端基础(基础知识)
java·开发语言·前端·数据库·学习·算法
海奥华21 小时前
go中的接口返回设计思想
开发语言·后端·golang
lifallen1 小时前
深入浅出 Arrays.sort(DualPivotQuicksort):如何结合快排、归并、堆排序和插入排序
java·开发语言·数据结构·算法·排序算法
运维开发王义杰1 小时前
Python: 告别 ModuleNotFoundError, 解决 pipx 环境下 sshuttle 缺少 pydivert 依赖的终极指南
开发语言·python