我正在尝试使用Matlab中的以下代码在傅里叶域中设计一个gabor滤波器组:
for i=1:u
for j = 1:v
theta =theta_list(j);
w_1_x=(centerFreq(1,i)*((m+1)/2)*cos(theta)); % size of filter and image is m-by-n
w_1_y=(centerFreq(2,i)*((n+1)/2)*sin(theta));
w_2_x=(-centerFreq(1,i)*((m+1)/2)*cos(theta));
w_2_y=(-centerFreq(2,i)*((n+1)/2)*sin(theta));
sigma=sqrt((w_1_x)^2+(w_1_y)^2);
sigma_H=sigma/(2*pi);
gF=fspecial('gaussian', [m,n], sigma_H);
gFilter1=circshift(gF, [round(w_1_x), round(w_1_y)]);
gFilter2=circshift(gF, [round(w_2_x), round(w_2_y)]);
gaborArray1{i,j} = 0.5*gFilter1+0.5*gFilter2;
gaborArray2{i,j} = 0.5*1i*gFilter1-0.5*1i*gFilter2;
gaborFilterBank{i,j}=gaborArray1{i,j}+1i.*gaborArray2{i,j};
end
end
但是,当我使用以下代码将滤镜转换为图像域并可视化滤镜的相位图时:
filter=ifft2(ifftshift(gaborFilterBank{i,j}));
phase=zeros(m, n);
for p=1:m
for q=1:n
phase(p,q)=atan(imag(filter(p,q)/real(filter(p,q)));
end
end
figure, imshow(phase, []);
我在滤镜的中心出现了奇怪的图案(如附图所示)。你能让我知道我的代码有什么问题吗?
答案 0 :(得分:0)
我发现了问题。而不是将中心坐标乘以[(m + 1)/ 2,(n + 1)/ 2],我应该将它们乘以[m,n]。更具体地说,而不是:
w_1_x=(centerFreq(1,i)*((m+1)/2)*cos(theta)); % size of filter and image is m-by-n
w_1_y=(centerFreq(2,i)*((n+1)/2)*sin(theta));
w_2_x=(-centerFreq(1,i)*((m+1)/2)*cos(theta));
w_2_y=(-centerFreq(2,i)*((n+1)/2)*sin(theta));
应该是:
w_1_x=(centerFreq(1,i)*m*cos(theta)); % size of filter and image is m-by-n
w_1_y=(centerFreq(2,i)*n*sin(theta));
w_2_x=(-centerFreq(1,i)*m*cos(theta));
w_2_y=(-centerFreq(2,i)*n*sin(theta));