I am trying to implement a gabor filter for use in textured image segmentation. I am doing this in MATLAB and consulting the concepts from paper - A level set and Gabor-based Active Contour Algorithm for Segmenting Textured Images
I am highlighing the relevant parts below: The 2D gabor function is given as
where
The frequency of the span-limited sinusoidal grating is given by F and its orientation is specified by Theta. Sigma is the scale parameter. This filter is to be used on an image and as the gabor filter consists of an imaginary component, the Gabor transform is obtained as shown below.
where, GR and GI are the real and imaginary parts obtained by convoluting it with an image u0. I need to code this part in MATLAB and generate the Gabor transformed image for the different values of theta, F and sigma
My code
clc;clear all;close all;
sigma=.0075;
m_size=7;
theta=pi/4;
F=60;
[real_g,im_g]=gabor(m_size,sigma,F,theta);
//My Gabor function
function [real_g,im_g] = gabor(m_size,sigma,F,theta)
[x,y]=meshgrid(1:m_size,1:m_size);
real_g = zeros(m_size);
im_g = zeros(m_size);
g_sigma = zeros(m_size);
for i=1:size(x,1)
for j=1:size(y,1)
g_sigma(i,j) = (1./(2*pi*sigma^2)).*exp(((-1).*(i^2+j^2))./(2*sigma^2));
real_g(i,j) = g_sigma(i,j).*cos((2*pi*F).*(i.*cos(theta)+j.*sin(theta)));
im_g(i,j) = g_sigma(i,j).*sin((2*pi*F).*(i.*cos(theta)+j.*sin(theta)));
end
end
My output
>> real_g
real_g =
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
>> im_g
im_g =
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
My gabor filter is completely wrong. Please could you guys help me to construct the correct gabor filter? Please note that the data for the parameters and the formula is taken from the paper I already referred.
Any help will be greatly appreciated. PS If anybody needs the paper I can mail it too. Thanks.