Edit: A description of the GABOR FILTER
% gab2d: **2D Gabor filter** % The Gabor filter is basically a Gaussian, modulated by a complex sinusoid % G = gab2d(I,Sx,Sy,f,theta,FUN) % Input and output arguments ([]'s are optional): % I (matrix) of size NxM: Input Image of size NxM. gamma (scalar): The spatial aspect ratio, x to y. lambda(scalar): The wavelength of the sinusoidal function. b (scalar): The spatial frequency band-width (in octaves) theta (scalar): The orientation of the gabor filter. % phi (scalar): The phase offset. 0 is real part of Gabor filter or % even-symmetric, pi/2 is imaginary part of Gabor filter or % odd-symmetric. % **Note**: sigma (scalar): The spread of Gabor filter or the standard % deviation of Gaussian is automatically computed from lambda and b. % [shape] (strings): Shape for conv2. See help conv2. Default is 'same'. % % GO (matrix) of size NxM: Output images which was applied Gabor % filters. This is the magnitude response. % [GF] (matrix) of size (2Sx+1)x(2Sy+1): Gabor filter.
function [GO, GF] = gab2d(I, gamma, lambda, b, theta, phi, shape)
I=imread('C:\Users\Vinay\Documents\MATLAB\textureflawimages\text9.png');
gamma = 1; b = 1; theta = 0:pi/6:pi-pi/6; phi = 0; shape = 'valid'; lambda=8;
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(fix(Sy)+y+1,fix(sigma)+x+1) = ...
exp(-.5*(xp^2+gamma^2*yp^2)/sigma^2) * cos(2*pi*xp/lambda+phi) ...
; %/ (2*pi*(sigma^2/gamma));
% Normalize if you use different sigma (lambda or b)
end
end
GO = conv2(I, double(GF), shape);
Error:
??? Error using ==> mpower Matrix must be square.
Error in ==> gab2d at 36 GF(fix(Sy)+y+1,fix(sigma)+x+1) = ...
I am somehow not able to rectify this problem ..
Please help