读进一幅图,二进制化,也就是说比如200X120的矩阵,只有黑白,要么1,要么0.
用网格把它打成10X10的格子图,每格就有个20X12的小矩阵。然后
for i = 1:10
...
for j = 1:10
这两个FOR就是对这100个格子逐个进行分析,从格子1,一直到格子100,但实际上后面就发现是对对这100个格子的边缘格子进行分析 ,中间不动(就是假设 边缘最没用,脸液轮不会出现在那儿,能扔就扔掉)
if (y2<=c | y2>=9*c) | (x1==1 | x2==r*10) % 保证是在边缘的格子里面
loc=find(BW(x1:x2, y1:y2)==0)% 这个格子(矩阵)里,有多少值为0的元素,即为背景元素,没用的,不是人脸。(所以这段 程序开头写了“将背景部分弱化”。
[o p]=size(loc)% 噢,找到了这么多个0
pr=o*100/s
% 用pr值 来判断是否应该将这整个格子全部值 赋为0,比如一个格子里面只有几个1(比如几根头发),其它全是无用的信息0,那么干脆就把这个格子全部变成0,免得影响判断。pr的定义是有问闹竖信题的,因为o永远小于s(你可以自己算算),所以所有的边缘格都会强行被赋为0,就是“全黑了”。
if pr<=100
BW(x1:x2, y1:y2)=0
r1=x1r2=x2s1=y1s2=y2% 这句话P用没有,整个程序前后都没出现r1,r2,s1,s2,在这儿定义有什么用?
pr1=0%同样是句P话,其他地方都没出现过pr1
end
end
y1=y1+c
y2=y2+c
end
x1=x1+r
x2=x2+r
然后这几句就是格子赋值 结束,继续前进,找下一个格子呗,又回到初始。。。
所以,上面这段程序,什么人脸不人脸检测的,就是把边缘全部变黑而己……
所以下纤姿面我也看不进去了。。。
补充:
还是说完吧,后面一段程序,其实就是把所有变黑的边缘的边界给勾了出来。没有任何新东西。。。
所以你这段程序,就是先把边缘全部抹黑,然后勾出这个边缘的边界,画出来,就行了。没有任何“人脸定位”的东西,就是假设人脸在图的中间,边缘没有任何信息。。。仅此而己~~~
function pca (path, trainList, subDim)%
% PROTOTYPE
% function pca (path, trainList, subDim)
%
% USAGE EXAMPLE(S)
% pca ('C:/FERET_Normalised/', trainList500Imgs, 200)
%
% GENERAL DESCRIPTION
% Implements the standard Turk-Pentland Eigenfaces method. As a final
% result, this function saves pcaProj matrix to the disk with all images
% projected onto the subDim-dimensional subspace found by PCA.
%
% REFERENCES
% M. Turk, A. Pentland, Eigenfaces for Recognition, Journal of Cognitive
% Neurosicence, Vol. 3, No. 1, 1991, pp. 71-86
%
% M.A. Turk, A.P. Pentland, Face Recognition Using Eigenfaces, Proceedings
% of the IEEE Conference on Computer Vision and Pattern Recognition,
% 3-6 June 1991, Maui, Hawaii, USA, pp. 586-591
%
%
% INPUTS:
% path - full path to the normalised images from FERET database
% trainList - list of images to be used for training. names should be
% without extension and .pgm will be added automatically
% subDim - Numer of dimensions to be retained (the desired subspace
% dimensionality). if this argument is ommited, maximum
% non-zero dimensions will be retained, i.e. (number of training images) - 1
%
% OUTPUTS:
% Function will generate and save to the disk the following outputs:
% DATA - matrix where each column is one image reshaped into a vector
% - this matrix size is (number of pixels) x (number of images), uint8
% imSpace - same as DATA but only images in the training set
% psi - mean face (of training images)
% zeroMeanSpace - mean face subtracted from each row in imSpace
% pcaEigVals - eigenvalues
% w - lower dimensional PCA subspace
% pcaProj - all images projected onto a subDim-dimensional space
%
% NOTES / COMMENTS
% * The following files must either be in the same path as this function
% or somewhere in Matlab's path:
% 1. listAll.mat - containing the list of all 3816 FERET images
%
% ** Each dimension of the resulting subspace is normalised to unit length
%
% *** Developed using Matlab 7
%
%
% REVISION HISTORY
% -
%
% RELATED FUNCTIONS (SEE ALSO)
% createDistMat, feret
%
% ABOUT
% Created: 03 Sep 2005
% Last Update: -
% Revision: 1.0
%
% AUTHOR: Kresimir Delac
% mailto: kdelac@ieee.org
% URL: http://www.vcl.fer.hr/kdelac
%
% WHEN PUBLISHING A PAPER AS A RESULT OF RESEARCH CONDUCTED BY USING THIS CODE
% OR ANY PART OF IT, MAKE A REFERENCE TO THE FOLLOWING PAPER:
% Delac K., Grgic M., Grgic S., Independent Comparative Study of PCA, ICA, and LDA
% on the FERET Data Set, International Journal of Imaging Systems and Technology,
% Vol. 15, Issue 5, 2006, pp. 252-260
%
% If subDim is not given, n - 1 dimensions are
% retained, where n is the number of training images
if nargin <3
subDim = dim - 1
end
disp(' ')
load listAll
% Constants
numIm = 3816
% Memory allocation for DATA matrix
fprintf('Creating DATA matrix\n')
tmp = imread ( [path char(listAll(1)) '.pgm'] )
[m, n] = size (tmp)% image size - used later also!!!
DATA = uint8 (zeros(m*n, numIm))% Memory allocated
clear str tmp
% Creating DATA matrix
for i = 1 : numIm
im = imread ( [path char(listAll(i)) '.pgm'] )
DATA(:, i) = reshape (im, m*n, 1)
end
save DATA DATA
clear im
% Creating training images space
fprintf('Creating training images space\n')
dim = length (trainList)
imSpace = zeros (m*n, dim)
for i = 1 : dim
index = strmatch (trainList(i), listAll)
imSpace(:, i) = DATA(:, index)
end
save imSpace imSpace
clear DATA
% Calculating mean face from training images
fprintf('Zero mean\n')
psi = mean(double(imSpace'))'
save psi psi
% Zero mean
zeroMeanSpace = zeros(size(imSpace))
for i = 1 : dim
zeroMeanSpace(:, i) = double(imSpace(:, i)) - psi
end
save zeroMeanSpace zeroMeanSpace
clear imSpace
% PCA
fprintf('PCA\n')
L = zeroMeanSpace' * zeroMeanSpace% Turk-Pentland trick (part 1)
[eigVecs, eigVals] = eig(L)
diagonal = diag(eigVals)
[diagonal, index] = sort(diagonal)
index = flipud(index)
pcaEigVals = zeros(size(eigVals))
for i = 1 : size(eigVals, 1)
pcaEigVals(i, i) = eigVals(index(i), index(i))
pcaEigVecs(:, i) = eigVecs(:, index(i))
end
pcaEigVals = diag(pcaEigVals)
pcaEigVals = pcaEigVals / (dim-1)
pcaEigVals = pcaEigVals(1 : subDim)% Retaining only the largest subDim ones
pcaEigVecs = zeroMeanSpace * pcaEigVecs% Turk-Pentland trick (part 2)
save pcaEigVals pcaEigVals
% Normalisation to unit length
fprintf('Normalising\n')
for i = 1 : dim
pcaEigVecs(:, i) = pcaEigVecs(:, i) / norm(pcaEigVecs(:, i))
end
% Dimensionality reduction.
fprintf('Creating lower dimensional subspace\n')
w = pcaEigVecs(:, 1:subDim)
save w w
clear w
% Subtract mean face from all images
load DATA
load psi
zeroMeanDATA = zeros(size(DATA))
for i = 1 : size(DATA, 2)
zeroMeanDATA(:, i) = double(DATA(:, i)) - psi
end
clear psi
clear DATA
% Project all images onto a new lower dimensional subspace (w)
fprintf('Projecting all images onto a new lower dimensional subspace\n')
load w
pcaProj = w' * zeroMeanDATA
clear w
clear zeroMeanDATA
save pcaProj pcaProj
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)