眼底图像血管增强与分割--(2)Gabor滤波算法原理及实现

http://blog.csdn.net/piaoxuezhong/article/details/78213672中介绍了匹配滤波算法用于血管分割,本篇继续介绍血管分割的另一种方法:Gabor滤波算法,具体可以参见论文《Retinal Vessel Segmentation Using the 2-D GaborWavelet and Supervised Classification》。

Gabor滤波算法

维基里给出的解释,“In image processing, aGabor filter is a linear filter used fortextureanalysis, which means that it basically analyses whether there are any specific frequency content in the image in specific directions in a localized region around the point or region of analysis. Frequency and orientation representations of Gabor filters are similar to those of thehuman visual system, and they have been found to be particularly appropriate for texture representation and discrimination. In the spatial domain, a 2D Gabor filter is aGaussiankernel function modulated by asinusoidal plane wave.”

我这里大概翻译一下:Gaoor滤波是用于纹理分析的线性滤波器,它可以用来分析图像中某点或某区域周围在特定方向上是否存在特定的频率。Gaoor滤波器的频率和方向特性与人的视觉系统相似,尤其适合用于纹理表述方面。在空间域中,Gaoor滤波器是一种由正弦波调制而成的高斯核函数。扒下公式,毕竟数学是少不了的:

 

公式里的参数就不再说了,熟悉高斯函数的筒子自然就清楚了,这里说一下Gabor滤波与傅里叶变换的关系。

Gabor变换傅里叶变换的关系

经典Fourier变换反映的是信号的整体特性(时域,频域),而对于傅里叶频谱中的某一频率,我们无法得知这个频率是什么时候产生的。傅里叶变换是信号在整个时域内的积分,反映的是信号频率的整体统计特性,所以不具备局部信号分析的功能。Gabor滤波正是针对Fourier变换的这点不足设计的,为了从Fourier变换中提取局部信息,引入了时间局部化的窗函数,变为窗口Fourier变换。由于窗口Fourier变换只依赖于部分时间的信号,窗口Fourier变换又称为短时Fourier变换,又称Gabor变换。(这样就清楚多了...)

信号x(t)的Gabor变换可以表示为:

 

G_{x}(t,f)=\int _{​{-\infty }}^{\infty }e^{​{-\pi (\tau -t)^{2}}}e^{​{-j2\pi f\tau }}x(\tau )\,d\tau

高斯函数分布如下图所示:

高斯分布虽然是无穷范围,但可以选取部分区域,例如设置阈值0.00001,下式成立:

{\begin{cases}e^{​{-{\pi }a^{2}}}\geq 0.00001;&\left|a\right|\leq 1.9143\\e^{​{-{\pi }a^{2}}}<0.00001;&\left|a\right|>1.9143\end{cases}}

Gabor变换可以近似为如下形式,即忽略掉了阈值外的区域:

G_{x}(t,f)=\int _{​{-1.9143+t}}^{​{1.9143+t}}e^{​{-\pi (\tau -t)^{2}}}e^{​{-j2\pi f\tau }}x(\tau )\,d\tau

二维Gabor滤波器--图像处理领域中的应用

二维Gabor滤波器能够很好地描述空间频率、空间位置和方向选择等局部信息,而且对光照不敏感。同时Gabor滤波器的响应和脊椎动物大脑视觉皮层简单细胞的响应非常相似。Gabor滤波在光学字符识别、虹膜识别和指纹识别等图像处理应用中非常有用。

 

(这个考验数学功底了)从g(x,y)的形式来看,二维Gabor滤波函数可以看成经过正弦函数调制的广义高斯函数,当然也可以根据正弦函数的分解对g(x,y)进行进一步的分解。至于进一步的解析可以查阅论文《二维Gabor滤波器的快速实现》。

Gabor滤波算法实现

(1)使用opencv实现Gabor

 

Mat mkKernel(int ks, double sig, double th, double lm, double ps)
{
	int halfks = (ks - 1) / 2;
	double theta = th*CV_PI / 180;
	double psi = ps*CV_PI / 180;
	double delta = 2.0 / (ks - 1);
	double lmbd = lm;
	double sigma = sig / ks;
	double x_theta;
	double y_theta;
	Mat GaborKernel(ks, ks, CV_32F);
	for (int y = -halfks; y <= halfks; y++)
	{
		for (int x = -halfks; x <= halfks; x++)
		{
			x_theta = x*delta*cos(theta) + y*delta*sin(theta);
			y_theta = -x*delta*sin(theta) + y*delta*cos(theta);
			GaborKernel.at<float>(halfks + y, halfks + x) = (float)exp(-0.5*(pow(x_theta, 2) + pow(y_theta, 2)) / pow(sigma, 2))* cos(2 * CV_PI*x_theta / lmbd + psi);
		}
	}
	return GaborKernel;
}

在网上流传比较广的是ZhouMian写的opencv实现,感兴趣的可以查看:http://download.csdn.net/download/piaoxuezhong/10033028.

(2)使用matlab实现Gabor

 

function [OutImg, GaborFilter] = gabor(I, gamma, lambda, b, theta, phi, shape)
if nargin < 7, shape = 'same'; end;
if isa(I, 'double') ~= 1, I = double(I); end
sigma = (1 / pi) * sqrt(log(2)/2) * (2^b+1) / (2^b-1) * lambda;
Sy = sigma * gamma;
for x = -fix(sigma):fix(sigma)
    for y = -fix(Sy):fix(Sy)
        xp = x * cos(theta) + y * sin(theta);
        yp = y * cos(theta) - x * sin(theta);
        % GF is Gabor Filter
        GaborFilter(fix(Sy)+y+1,fix(sigma)+x+1) = ...
            exp(-.5*(xp^2+gamma^2*yp^2)/sigma^2) * cos(2*pi*xp/lambda+phi);
    end
end

OutImg = conv2(I, double(GaborFilter), shape);

end

 

另外,参照opencv的实现,matlab附带案例测试文件的链接如下:http://download.csdn.net/download/piaoxuezhong/10033075

这里,我只贴下效果图:

参考:

  • https://en.wikipedia.org/wiki/Gabor_filter
  • http://www.cppblog.com/polly-yang/archive/2012/07/14/183327.aspx
  • http://blog.csdn.net/watkinsong/article/details/7872764
  • http://blog.csdn.net/chenbang110/article/details/7561846
  • https://blog.csdn.net/dxinbin/article/details/73250571        ---matlab---
  • http://blog.csdn.net/watkinsong/article/details/7876361     ---matlab---
  • http://blog.csdn.net/u013288466/article/details/72636485
  • http://blog.csdn.net/jinshengtao/article/details/17797641   ---opencv---
  • http://blog.csdn.net/lichengyu/article/details/24534245
  • http://blog.csdn.net/lichengyu/article/details/20743877       ---opencv---
  • https://code.google.com/p/gaborboosting/source/checkout
  • http://blog.csdn.net/jbb0523/article/details/42028587
  • 《利用2D-Gabor滤波器提取纹理方向特征的虹膜识别方法》[J].计算机应用研究
  • 《二维Gabor滤波器的快速实现》[J]自动化学报
  • 《Gabor-Boosting Face Recognition》

 

附录几篇视网膜血管分割的文章:

  • https://wenku.baidu.com/view/f42a5018763231126edb11f1.html
  • http://xueshu.baidu.com/s?wd=paperuri%3A%28746181cea26c0e0ae8243ebc001c6396%29&filter=sc_long_sign&tn=SE_xueshusource_2kduw22v&sc_vurl=http%3A%2F%2Fwww.doc88.com%2Fp-1428507894322.html&ie=utf-8&sc_us=12351080291907237713
  • 3
    点赞
  • 59
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
2D-FFT的Gabor滤波是一种常用的图像处理方法,可以用于提取掌纹等生物特征。以下是使用 Python 实现 2D-FFT的Gabor滤波提取掌纹特征的示例代码: ```python import cv2 import numpy as np from scipy import fftpack # 读取图像 img = cv2.imread('input.jpg', 0) # 定义Gabor滤波器的参数 ksize = 31 theta = np.pi / 4 sigma = 2 * np.pi gamma = 0.5 psi = 0 # 生成Gabor滤波器的实部和虚部 kernel_real = cv2.getGaborKernel((ksize, ksize), sigma, theta, gamma, 1, psi, ktype=cv2.CV_32F) kernel_imag = cv2.getGaborKernel((ksize, ksize), sigma, theta, gamma, 1, psi + np.pi/2, ktype=cv2.CV_32F) # 对图像进行2D-FFT img_fft = fftpack.fft2(img) # 将滤波器转换为频率域 kernel_real_fft = fftpack.fft2(kernel_real, s=img.shape) kernel_imag_fft = fftpack.fft2(kernel_imag, s=img.shape) # 将滤波器应用于频率域图像 filtered_real = np.real(fftpack.ifft2(img_fft * kernel_real_fft)) filtered_imag = np.real(fftpack.ifft2(img_fft * kernel_imag_fft)) # 计算Gabor滤波器响应的幅值 gabor_response = np.sqrt(filtered_real ** 2 + filtered_imag ** 2) # 显示结果 cv2.imshow('input', img) cv2.imshow('gabor_response', gabor_response) cv2.waitKey(0) cv2.destroyAllWindows() ``` 在这个例子中,我们首先使用 OpenCV 库中的 `cv2.imread()` 函数读取输入图像,并将其转换为灰度图像。然后,我们定义 Gabor 滤波器的参数,包括滤波器大小、方向、尺度、宽度和相位偏移等。 接下来,我们使用 OpenCV 库中的 `cv2.getGaborKernel()` 函数生成 Gabor 滤波器的实部和虚部。然后,我们使用 SciPy 库中的 `fftpack.fft2()` 函数对输入图像进行二维快速傅里叶变换,将其转换为频率域图像。 接下来,我们将 Gabor 滤波器转换为频率域,并使用 `fftpack.ifft2()` 函数将其应用于频率域图像。然后,我们计算 Gabor 滤波器响应的幅值,并使用 `cv2.imshow()` 函数显示输入图像Gabor 滤波器响应,并使用 `cv2.waitKey()` 和 `cv2.destroyAllWindows()` 函数等待用户按下键盘上的任意键以关闭窗口。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值