【图像检测】基于K-L实现人脸检测附matlab代码

1 内容介绍

人脸识别作为一种重要的个人身份鉴别方法,可广泛地应用于证件核对、公安追逃、信用卡验证、自动取款机(ATM)等方面..与利用指纹、手掌、视网膜、虹膜等其他人体生物特征进行人身鉴别的方法相比,人脸识别具有直接、友好、方便的特点.一个完整的人脸识别系统包括人脸检测、特征提取、以及匹配识别.人脸检测是其中的第一步,也是人脸识别系统的重要步骤.本文研究了对在几种不同的光照补偿方法处理后的图像上使用K-L算法及奇异值分解实现的人脸自动检测方法,提出了一种工程方法,该方法自动的选择适应指定"检测精度"的特征脸的个数,排除特征脸空间中能量值较小的特征轴,降低了选择特征脸空间中的能量集中的轴的工作难度.首先基于K-L展开式的特征提取,以输入样本中每个人的平均样本和所有人的平均样本组成类间离散矩阵,作为K-L变换的产生矩阵,对该矩阵进行奇异值分解,获得特征脸空间,同时得到训练样本在该空间得一组投影系数,即代数特征.其次,将待测图像向该空间投影,得到待测图像得代数特征.接着,对比待测图像和训练样本的代数特征,在对比过程中,根据指定的精度,选取对应适当的特征脸个数的训练样本的代数特征个数,与待测图像的代数特征求欧式距离,根据该距离检测待测图像是否是人脸.从实验结果可以看出,本文提出的方法具有一定的鲁棒性,可以适应样本训练个数变化较大的环境,同时可以有效的排除特征脸空间中能量值较小的特征轴,在训练样本比较多的情况下,可以有效的减少选择特征脸空间中能量值集中的轴的工作量.得到尽可能少且最有人脸代表性的特征脸子空间. 

2 部分代码

% Version : 4.1

% Author  : Omid Bonakdar Sakhi

function IMVECTOR = im2vec (W27x18)

%{

The input of the function is a 27x18 window . At first the function adjusts

the histogram of the window . Then to convolve the window with Gabor 

filters , the window in frequency domain will multiply by gabor filters

Gabor filters are stored in gabor.mat . to save time they have been saved 

in frequency domain before.

%} 

load gabor; %loading Gabor filters

% Adjust the window histogram , the parameters are set with try and error

W27x18 = adapthisteq(W27x18,'Numtiles',[8 3]); 

Features135x144 = cell(5,8);

for s = 1:5

    for j = 1:8

        Features135x144{s,j} = ifft2(G{s,j}.*fft2(double(W27x18),32,32),27,18);

    end

end

% Features135x144 is a cell array contains the result of the convolution of

% the window with each of the fourty gabor filters. These matrixes will

% concate to form a big 135x144 matrix of complex numbers/

% We only need the magnitude of the result That is why the abs is used.

Features135x144 = abs(cell2mat(Features135x144));

% 135x144 is very painful to be an input for the network . it has 19,400

% pixels . It means that the input vector of the network should have 19,400

% pixels which means a large amount of computation and waste of time.

% so We reduce the matrix size to one-third of it's original size.

% There are so many ways to reduce the matrix size like using PCA , using

% the median of each 3x3 pixels or deleting the rows and colums

% Deleting is not the best way , but it save more time compare with

% others

Features135x144 (3:3:end,:)=[];

Features135x144 (2:2:end,:)=[];

Features135x144 (:,3:3:end)=[];

Features135x144 (:,2:2:end)=[];

% The numbers in the input vector of the network should be between -1,1

% and the line below will fulfill this concept.

Features45x48 = premnmx(Features135x144);

% Change the matrix to a vector 

IMVECTOR = reshape (Features45x48,[2160 1]);

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

% notes : This function is very critical . consider that we have a big

% photo say 400x300 . Can you say how may 27x18 windows we have ? 

% If we do not preprocess the photo to predict the location of the faces

% we have a window for each and every single pixel of the photo which means

% 120,000 windows ( A little less because of the borders ) . and each pixel

% is the center of a new window.

% if this function takes .4 sec to be executed , the whole photo will take

% about 13 hours only for the network preprocess .

% so any unnecessary line in this function can be a hell for the whole 

% process and we should optimize this function as possible as we can.

3 运行结果

4 参考文献

[1]龙琰. 基于K-L变换的人脸检测[D]. 四川大学, 2004.

博主简介:擅长智能优化算法神经网络预测信号处理元胞自动机图像处理路径规划无人机雷达通信无线传感器等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是基于K-L变换人脸识别的MATLAB实现代码: ```matlab % 读入人脸数据库 faceDB = dir('faceDB/*.bmp'); % 将所有人脸图像作为矩阵存储在faces矩阵中 faces = []; for i = 1:length(faceDB) face = imread(['faceDB/' faceDB(i).name]); faces(:, i) = face(:); end % 求出平均脸 meanFace = mean(faces, 2); % 将所有脸减去平均脸,得到差异矩阵 diffFaces = faces - meanFace; % 计算差异矩阵的协方差矩阵 covMatrix = cov(diffFaces'); % 对协方差矩阵进行特征分解 [V, D] = eig(covMatrix); % 将特征向量作为新的基向量,构造投影矩阵 projectionMatrix = V'; % 将所有脸投影到新的基向量空间中 projectedFaces = projectionMatrix * diffFaces; % 读入测试图像 testFace = imread('test.bmp'); % 将测试图像投影到新的基向量空间中 projectedTestFace = projectionMatrix * (double(testFace(:)) - meanFace); % 计算测试图像与每个人脸的距离(采用欧氏距离) distances = sqrt(sum((projectedFaces - projectedTestFace).^2)); % 找出距离最近的人脸 [minDistance, index] = min(distances); % 显示结果 subplot(1, 2, 1); imshow(testFace); title('Test Face'); subplot(1, 2, 2); imshow(reshape(faces(:, index), size(testFace))); title(['Matched Face (distance = ' num2str(minDistance) ')']); ``` 注意,以上代码只是基于K-L变换人脸识别的简单实现,实际应用中还需要考虑更多因素,例如人脸图像的预处理、特征向量的选择、距离度量的优化等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值