I tried to apply a Gabor filter with a specific scale (according to my values of lambda and sigma, so it is (7x7) and for 4 orientations (0, $\frac{\pi}{4}$, $\frac{\pi}{2}$ and $\frac{3\pi}{4}$) to a input gray scale image.
In my code, three steps are achieved:
Create a Gabor Filter
Read an RGB image, then convert it to gray scale and finaly to double.
Apply the created gabor to the input image (here, i am not sure if my code is true, that's why i need your opinion )
1) -------------- create the Gabor filter (size=7x7 and 4 orientations)
%define the five parameters
theta=....; %either 0 or pi/4 or pi/2 or 3pi/4
lambda=3.5;
gamma=0.3;
sigma=2.8;
psi=0;
sigma_x = sigma;
sigma_y = sigma/gamma;
nstds = 5;
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);
figure(2);
imshow(gb);
title('theta=...');
%imagesc(gb);
%colormap(gray);
%title('theta=...');
2)------------Read the input image
I=imread('piano.jpg');
image_resize=imresize(I, [160,160]);
image_gray=rgb2gray(image_resize);
image_double=im2double(image_gray);
figure(1);
imshow(image_double);
3) -----apply the created above gabor to the input image (recall that i am not sure if the code in this step is 100% true, that's why i need your opinion and your help if you have the correct answer.)
figure(3);
filtered = conv2(image_double,gb);
imagesc(filtered);
colormap(gray);
title('theta=....');