同态滤波(Homomorphic filtering)(附源码)1

引言

一副图像f(x,y)f(x,y)的乘积,由于照度相对变化很小,可以看作是图像的低频成份,而反射率则是高频成份。通过分别处理照度和反射率对像元灰度值的影响,达到揭示阴影区细节特征的目的。

算法

对于一副图像f(x,y)f(x,y)

步骤

同态滤波(Homomorphic filtering)(附源码)1

同态滤波器的设计

% Use function dftuv to set up the meshgrid arrays needed for
% computing the required distances. 
[U, V] = dftuv(M, N);

% Compute the distances D(U, V).
 D = hypot(U, V);

% Begin filter computations.
H = (2-0.25)*[1 - exp(-(D.^2)./(D0^2))]+0.25;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

根据不同的图像特性和需要,选用不同的H(u,v),可得到满意的结果。常数cc之间过渡。这个滤波器类似于高斯高频强调滤波器。
源代码如下:

function Out = homomorphicfilter(I,cvar)
%=======================================
%  This function is the heart of the algo.
%  (a)  Filterings at several scales and sumarize the results.
%  (b)  Calculation of the final values.
[hei,wid,bytes] = size(I);
I = double(I);

R  = zeros(hei,wid,3,'single');
for channel = 1:3
    F = fft2(I(:,:,channel)+1.0);

    Hp = lpfilter('homogeneous',hei,wid,80);
    G = Hp.*F;
    g = ifft2(G);

    R(:,:,channel) = g;
end



OutMean = mean(R(:));
OutStd  = std(R(:));
mini = OutMean - cvar*OutStd;
maxi = OutMean + cvar*OutStd;
range = maxi - mini;

if range ==0
    range = 1;
end

Out = 255*(R - mini) / range;
Out = max(min(Out,255),0);
Out = uint8(Out);
end
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

其中函数lpfilter(‘homogeneous’,hei,wid,80)就是上面的同态滤波器。代码不可直接运行,需要把同态滤波完善一下就可以了。

效果

医学图像

同态滤波(Homomorphic filtering)(附源码)1

水下图像

同态滤波(Homomorphic filtering)(附源码)1

光照不均图像

同态滤波(Homomorphic filtering)(附源码)1

雾天图像

同态滤波(Homomorphic filtering)(附源码)1

评论

同态滤波是一个比较经典的算法,有论文说可以去雾,但经我测试,效果都不是很好。但对水中图像效果确是极好的。另外同态滤波主要用于预处理阶段去除光照不均的影响,这用顶帽变化也可以的。

参考资料

数字图像处理(第三版) 冈萨雷斯著 chapter 4,频率域滤波

转载请保留以下信息

作者 日期 联系方式
风吹夏天 2015年5月17日 [email protected]

引言