|
|
function g = gistGabor(img, w, G) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ndims(img)==2 |
|
|
c = 1; |
|
|
N = 1; |
|
|
end |
|
|
if ndims(img)==3 |
|
|
[nrows ncols c] = size(img); |
|
|
N = c; |
|
|
end |
|
|
if ndims(img)==4 |
|
|
[nrows ncols c N] = size(img); |
|
|
img = reshape(img, [nrows ncols c*N]); |
|
|
N = c*N; |
|
|
end |
|
|
|
|
|
[n n Nfilters] = size(G); |
|
|
W = w*w; |
|
|
g = zeros([W*Nfilters N]); |
|
|
|
|
|
img = single(fft2(img)); |
|
|
k=0; |
|
|
for n = 1:Nfilters |
|
|
ig = abs(ifft2(img.*repmat(G(:,:,n), [1 1 N]))); |
|
|
v = downN(ig, w); |
|
|
g(k+1:k+W,:) = reshape(v, [W N]); |
|
|
k = k + W; |
|
|
drawnow |
|
|
end |
|
|
|
|
|
if c == 3 |
|
|
|
|
|
|
|
|
g = reshape(g, [size(g,1)*3 size(g,2)/3]); |
|
|
end |
|
|
|
|
|
|
|
|
function y=downN(x, N) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nx = fix(linspace(0,size(x,1),N+1)); |
|
|
ny = fix(linspace(0,size(x,2),N+1)); |
|
|
y = zeros(N, N, size(x,3)); |
|
|
for xx=1:N |
|
|
for yy=1:N |
|
|
v=mean(mean(x(nx(xx)+1:nx(xx+1), ny(yy)+1:ny(yy+1),:),1),2); |
|
|
y(xx,yy,:)=v(:); |
|
|
end |
|
|
end |
|
|
|