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.