Create a Gabor filter by applying Gabor equation using matlab
我尝试创建一个 Gabor 过滤器。我们都知道这种过滤器比任何其他过滤器都更复杂,因为它的特点是具有更复杂的特征,例如具有不同的尺度和方向。
Gabor 滤波器的方程为:
为了创建这样一个具有特定尺度和方向的 Gabor 滤波器,维基百科给了我们一个简单的 matlab 代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | sigma_x = sigma; sigma_y = sigma/gamma; nstds = 3; xmax = max(abs(nstds*sigma_x*cos(theta)),abs(nstds*sigma_y*sin(theta))); xmax = ceil(max(1,xmax)); ymax = max(abs(nstds*sigma_x*sin(theta)),abs(nstds*sigma_y*cos(theta))); ymax = ceil(max(1,ymax)); xmin = -xmax; ymin = -ymax; [x,y] = meshgrid(xmin:xmax,ymin:ymax); x_theta=x*cos(theta)+y*sin(theta); y_theta=-x*sin(theta)+y*cos(theta); gb= exp(-.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi); |
我想知道这段代码是否正确。我注意到上面的代码没有完全响应 Gabor 滤波器的方程。例如:在代码中,我们有 :
上面写的matlab代码是否正确响应了Gabor滤波器的方程??请我需要你的意见,如果可能的话优化代码,如果它不正确。
任何帮助将不胜感激。
替换代码中的以下行:
我在上面的matlab代码中用sin替换了cos。
您现在可以使用图像处理工具箱中的 gabor 函数创建 Gabor 滤波器组,并且可以使用 imgaborfilt 将其应用于图像。
公式为 exp(-(...) / (2*sigma^2) )。不是吗?
所以 1/2 = 0.5 = .5