您的位置:首页 > 其它

人脸识别---人脸图像预处理

2015-11-11 11:03 656 查看
Abstrcat—人脸图像预处理是为了去除光照对人脸影响。

通常我们采用直方图均衡化对人脸图像进行处理。下面介绍一个方法对人脸进行预处理,由于没有找到相关文献的介绍,现在只能给出公式以及该方法与直方图均衡化后的结果。该方法最终得到识别率比直接采用直方图均衡化好。

对于一幅尺寸为m∗n 人脸图像I .

I 1 =I(∑ m i=1 ∑ n j=1 |I ij | a /(m∗n)) (1/a)

I 2 =I 1 (∑ m i=1 ∑ n j=1 min(trim,|I ij |) a /(m∗n)) (1/a)

I 3 =trim∗tanh(Itrim )

其中trim=10

下图是均衡化和本方法的处理结果图



最左边的图是原始光照不强的人脸图像,中间是均衡化后图像,右边通过本文方法提取的图像。可以看出右图处理已经有了一定的纹理特性,实验表明对后续人脸识别有帮助。

psTan.m

function img = psTan(imgRaw)

% parameter setting for preprocessing
gamma = 0.2;    % gamma parameter
sigma0 = 1;   % inner Gaussian size
sigma1 = -2;   % outer Gaussian size
sx = 0;       % x offset of centres of inner and outer filter
sy = 0;       % y offset of centres of inner and outer filter
mask = [];    % mask
do_norm = 10;  % Normalize the spread of output values

% preprocessing face images.......
im1=double(imgRaw);

img = preproc2(im1,gamma,sigma0,sigma1,[sx,sy],mask,do_norm);


preproc2.m

function im = preproc2(im,gamma,sigma0,sigma1,shift,mask,do_norm)

% Gamma correct input image to increase local contrast in shadowed
% regions.
if gamma == 0
im = log(im+max(1,max(max(im)))/256);
else
im = im.^gamma;
end

% run prefilter, if any
if sigma1
border=1;
if border % add extend-as-constant image border to reduce
% boundary effects
[m,n] = size(im);
b=floor(3*abs(sigma1));
c=ones(b); d=ones(b,1);
im = [ c*im(1,1), d*im(1,:), c*im(1,n);...
im(:,1)*d', im, im(:,n)*d';...
im(m,1)*c, d*im(m,:), c*im(m,n) ];
end
if sigma1>0
% Build difference of gaussian filter and apply it to image.
[x,y,r] = fftcoord(size(im,1),size(im,2));
g0 = exp(-0.5*(r/max(sigma0,1e-6)).^2);
g0 = g0./sum(sum(g0));
g1 = exp(-0.5*(r/max(sigma1,1e-6)).^2);
if ~isempty(shift)
g1 = circshift(g1,shift);
end
g1 = g1./sum(sum(g1));
im = real(ifft2(fft2(im).*fft2(g0-g1)));
else  % sigma1<0, alternative implementation using explicit convolution
if sigma0>0
im = gaussianfilter(im,sigma0)-gaussianfilter(im,-sigma1,shift);
else
im = im-gaussianfilter(im,-sigma1,shift);
end
end
if border
im = im(b+(1:m),b+(1:n));
end
end

if ~isempty(mask) % mask out unwanted pixels
im=im.*mask;
end

if do_norm
a = 0.1;
trim = abs(do_norm);
im = im./mean(mean(abs(im).^a))^(1/a);
im = im./mean(mean(min(trim,abs(im)).^a))^(1/a);
if do_norm>0
% trim/squash any large outliers (e.g. specularities) if
% required. Can be omitted if your descriptor / image
% display method is not sensitive to these.

% im = min(trim,max(-trim,im)); % truncate
im = trim*tanh(im/trim); % squash with tanh sigmoid
end
end

% end


gaussianfilter.m

function imgResult=gaussianfilter(img,sigma,shift)

if max(size(sigma))==1, sigma=[sigma sigma]; end
if nargin<3 || isempty(shift), shift = 0; end
if max(size(shift)) == 1, shift=[shift shift]; end

%x = [floor(-3.0*sigma+0.5):floor(3.0*sigma+0.5)];
Gx = gauss([ceil(-3.0*sigma(1)-0.5-shift(1)):floor(3.0*sigma(1)+0.5-shift(1))],sigma(1));
Gy = gauss([ceil(-3.0*sigma(2)-0.5-shift(2)):floor(3.0*sigma(2)+0.5-shift(2))],sigma(2));
imgTmp    = conv2(img,Gx,'same');
imgResult = conv2(imgTmp,Gy','same');

end


gauss.m

function G=gauss(x,sigma)

%G = exp(-x.^2/(2*sigma^2))/(sqrt(2*pi)*sigma);
G = exp(-x.^2/(2*sigma^2));
G=G/sum(sum(G));

end


fftcoord.m

% matrices with x,y and radial frequency coordinates of corresponding
% entry of fft matrix

function [x,y,r] = fftcoord(m,n)

if nargin<2
m2 = ceil(m/2);
x = [0:m2-1,m2-m:-1];
else
m2 = ceil(m/2);
n2 = ceil(n/2);
x = ([0:m2-1, m2-m:-1])'*ones(1,n);
if nargout>=2
y = ones(m,1)*([0:n2-1, n2-n:-1]);
if nargout>=3
r = sqrt(x.^2+y.^2);
% r(1,1) = 1e-8;
end
end
end
% end


调用方式:

src输入为灰度图像: dst = psTan(src);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  脸部识别