Visualizing Gabor filters using mesh

5 visualizaciones (últimos 30 días)
Guru Swaroop
Guru Swaroop el 26 de Jul. de 2014
Editada: Guru Swaroop el 2 de Oct. de 2015
Now, I have implemented the Gabor filter as : In my_gabor_filter.m, I have the following code :
function psi = my_gabor_filter(x,y,mu,nu,sigma)
phi = pi*mu/8;
f = sqrt(2);
k_max = pi/2;
k_nu = k_max/(f^nu);
k_vec = [k_nu*cos(phi),k_nu*sin(phi)]';
z_vec = [x,y]';
k_vec_norm = norm(k_vec);
z_vec_norm = norm(z_vec);
exp1 = (k_vec_norm/(sigma^2));
exp2 = (exp(-((k_vec_norm^2)*(z_vec_norm^2)/(2*sigma^2))));
exp3 = (exp(complex(0,k_vec'*z_vec))-exp(-(sigma^2/2)));
psi = exp1*exp2*exp3;
end
and, in plot_gabor_filter.m I did the following :
function plot_gabor_filter()
mu = 0;
nu = 0;
sigma = 1;
[X,Y] = meshgrid(0:1:39,0:1:39);
Z = my_gabor_filter(X, Y, mu, nu, sigma);
mesh(X,Y,Z,'EdgeColor','black')
end and when I run plot_gabor_filter.m, I get the following output :
>> plot_gabor_filter
Error using *
Inner matrix dimensions must agree.
Error in my_gabor_filter (line 17)
exp3 = (exp(complex(0,k_vec'*z_vec))-exp(-(sigma^2/2)));
Error in plot_gabor_filter (line 16)
Z = my_gabor_filter(X.^1 ,Y.^1,mu,nu,sigma);
So I have come this far. Kindly help me.

Respuesta aceptada

Guru Swaroop
Guru Swaroop el 27 de Jul. de 2014
The problem was, that, I was passing X and Y as matrices, which my_gabor_filter(..) cannot handle correctly, so instead I evaluated my_gabor_filter at each point (x,y) with x in X and y in Y, and so the modified version of my_gabor_filter is as follows :
NOTE : I also adjusted the range for X and Y so that the mesh-grid is clearly seen
function plot_gabor_filter()
mu = 0;
nu = 0;
sigma = 1;
[X,Y] = meshgrid(-2:0.1:2,-2:0.1:2);
Z = zeros(41,41);
for i = 1:1:41
for j = 1:1:41
Z(i,j) = imag(my_gabor_filter(X(i,j),Y(i,j),mu,nu,sigma));
end
end
surf(X,Y,Z,'EdgeColor','black')
xlabel('x axis');
ylabel('y axis');
zlabel('g(x,y)');
end
and, This solves my problem.

Más respuestas (1)

Wayne King
Wayne King el 26 de Jul. de 2014
Unless you have posted the incorrect version of my_gabor_filter.m, I show that it errors on this line actually:
exp3 = (exp(complex(0,k_vec'*z_vec))-exp(-(sigma^2/2)));
k_vec is 2x1 and z_vec is 80x40 so multiplying k_vec' and z_vec is not going to work.
  1 comentario
Guru Swaroop
Guru Swaroop el 27 de Jul. de 2014
Editada: Guru Swaroop el 2 de Oct. de 2015
Yaa thats right, because while designing my_gabor_filter() I was assuming that x and y are not matrices, but single valued (or matrices of size 1X1). So I fixed plot_gabor_filter as shown here.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by