光照归一化算法——DoG滤波,自商图

DoG code:
function pic=DoG(I)
if size(I,3)==3
    I=rgb2gray(I);
end
I=double(I);
h1=fspecial('gaussian',15,1);
h2=fspecial('gaussian',15,2);
m=filter2(h2,I)-filter2(h1,I);
R=m;
mi=min(min(R));
ma=max(max(R));
newR=(R-mi)*255/(ma-mi);
pic=uint8(newR);

处理效果:

光照归一化算法——DoG滤波,自商图_第1张图片

光照归一化算法——DoG滤波,自商图_第2张图片

理论:

Given a m-channels, n-dimensional image

I:\{\mathbb{X}\subseteq\mathbb{R}^n\}\rightarrow\{\mathbb{Y}\subseteq\mathbb{R}^m\}

The difference of Gaussians (DoG) of the image I is the function

\Gamma_{\sigma_1,\sigma_2}:\{\mathbb{X}\subseteq\mathbb{R}^n\}\rightarrow\{\mathbb{Z}\subseteq\mathbb{R}\}

obtained by subtracting the image Iconvolved with the Gaussian of variance \sigma^2_2 from the imageIconvolved with a Gaussian of narrower variance \sigma^2_1, with\sigma_2 > \sigma_1. In one dimension,\Gamma is defined as:

\Gamma_{\sigma_1,\sigma_2}(x)=I*\frac{1}{\sigma_1\sqrt{2\pi}} \, e^{-(x^2)/(2\sigma^2_1)}-I*\frac{1}{\sigma_2\sqrt{2\pi}} \, e^{-(x^2)/(2\sigma_2^2)}.

and for the centered two-dimensional case :

\Gamma_{\sigma,K\sigma}(x,y)=I*\frac{1}{2\pi \sigma^2} e^{-(x^2 + y^2)/(2 \sigma^2)} - I*\frac{1}{2\pi K^2 \sigma^2}  e^{-(x^2 + y^2)/(2 K^2 \sigma^2)}

which is formally equivalent to:

\Gamma_{\sigma,K\sigma}(x,y)=I*(\frac{1}{2\pi \sigma^2} e^{-(x^2 + y^2)/(2 \sigma^2)} - \frac{1}{2\pi K^2 \sigma^2}  e^{-(x^2 + y^2)/(2 K^2 \sigma^2)})

which represents an image convoluted to the difference of two Gaussians, which approximates aMexican Hat function.

自商图code:

function [pic,ipic]=selfQuotient(I)
if size(I,3)==3
G=rgb2gray(I);
else
    G=I;
end
G=double(G);
G=(G-min(min(G)))/(max(max(G))-min(min(G)))*255;%对比度拉升
% thr=mean(G);
% w=zeros(rows,cols);
% for i=1:rows
%     for j=1:cols
%         if(I(i,j)>thr)
%             w(i,j)=0;
%         else
%             w(i,j)=1;
%         end
%     end
% end
h1=fspecial('gaussian',7,1);
% h1=h1.*w;
f1=filter2(h1,G);
R=G./f1;
mi=min(min(R));
ma=max(max(R));
newR=(R-mi)*255/(ma-mi);
pic=uint8(newR);
ipic=uint8(f1);
处理效果图:

光照归一化算法——DoG滤波,自商图_第3张图片光照归一化算法——DoG滤波,自商图_第4张图片


ps:

自商图求滤波器h1的时候,赋了权值,不过实验中发现不设置权值效果似乎更佳,所以注释掉了权值部分。权值的设置应该是一个值得探讨的部分。

你可能感兴趣的:(数字图像处理,人脸识别)