-
Notifications
You must be signed in to change notification settings - Fork 2
/
gaborFilterBank.m
69 lines (56 loc) · 2.23 KB
/
gaborFilterBank.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function gaborArray = gaborFilterBank(u,v,m,n)
% GABORFILTERBANK generates a custum Gabor filter bank.
% It creates a u by v cell array, whose elements are m by n matrices;
% each matrix being a 2-D Gabor filter.
%
%
% Inputs:
% u : No. of scales (usually set to 4)
% v : No. of orientations (usually set to 8)
% m : No. of rows in a 2-D Gabor filter (an odd integer number, usually set to 39)
% n : No. of columns in a 2-D Gabor filter (an odd integer number, usually set to 39)
%
% Output:
% gaborArray: A u by v array, element of which are m by n
% matries; each matrix being a 2-D Gabor filter
if (nargin ~= 4) % Check correct number of arguments
error('There must be four input arguments (Number of scales and orientations and the 2-D size of the filter)!')
end
%% Create Gabor filters
% Create u*v gabor filters each being an m by n matrix
gaborArray = cell(1,v);
fmax = 3;
gama = sqrt(2);
eta = sqrt(2);
for i = u
fu = fmax/((sqrt(2))^(i-1));
alpha = fu/gama;
beta = fu/eta;
for j = 1:v
tetav = ((j-1)/(v-1))*pi;
gFilter = zeros(m,n);
for x = 1:m
for y = 1:n
xprime = (x-((m+1)/2))*cos(tetav)+(y-((n+1)/2))*sin(tetav);
yprime = -(x-((m+1)/2))*sin(tetav)+(y-((n+1)/2))*cos(tetav);
gFilter(x,y) = (fu^2/(pi*gama*eta))*exp(-((alpha^2)*(xprime^2)+(beta^2)*(yprime^2)))*exp(1i*2*pi*fu*xprime);
end
end
gaborArray{1,j} = gFilter;
end
end
%% Show Gabor filters (Please comment this section if not needed!)
% Show magnitudes of Gabor filters:
% figure('NumberTitle','Off','Name','Magnitudes of Gabor filters');
% for i = u
% for j = 1:v
% %subplot(u,v,(i-1)*v+j);
% subplot(2,v,j);
% imshow(abs(gaborArray{1,j}),[]);title('Magnitude');
% hold on;
% subplot(2,v,j+v);
% imshow(real(gaborArray{1,j}),[]);title('Orientation');
% hold off;
% end
% end
end