如何使用傅里叶变换找到图像的方向?

时间:2016-05-23 04:03:08

标签: matlab image-processing

如何使用fft查找方向?这是一个想法(reference paper

1. Find the fft2 x(u,v)=fft2(x(x,y))

2. ur=sqrt(u.^2+V.^2),theta=atan2(v,u)  

3. X(ur,theta)=x(ur*cos(theta),ur*sin(theta))  

4. power of dft p(ur,theta)=abs(X(ur,theta).^2)  

5. found the angular DFT by summing the power of annual band between radial frequency ur1 and ur2  
A(theta)=sum(p(ur,theta))

我的问题是如何实施最后一步?这是我尝试但无法理解最后一步的代码。 Matlab代码:

    t=imread('untitled5.png');
    fontSize=12
    [m,n]=size(t);
    img=fftshift(t(:,:,2));
    g=fft2(img);
    c = g .* conj(g) ;
    d=fft2(c);

image for orienatation

1 个答案:

答案 0 :(得分:2)

imgOrg=imread('untitled5.png');
imgGray=rgb2gray(imgOrg);
dft=fft2(imgGray);
dftCentered=fftshift(dft);
ur=abs(dftCentered);
theta=angle(dftCentered);
X_new=ur.*(cos(theta)+(1i.*sin(theta)));
P=abs(X_new).^2;
imshow(mat2gray(log(P)));

现在你必须创建面具。这是掩模应该如何的参考。阅读Frequency Orientation Page 70

Pixels between 2 intersecting lines

开头

创建一个与图像具有相同尺寸的蒙版,并将其与P多个并对矩阵求和。你会得到A(Theta)那个方向。如果第一个掩码位于mask(:,:,1),并且您有4个掩码(mask(:,:,1),mask(:,:,2),mask(:,:,3),mask(:,:,4))。然后其余的代码将是。

for indexTheta=1:4
    A(indexTheta)=sum(sum(P.*mask(:,:,indexTheta)));
end

现在,您将获得四个方向A。现在你已经完成了。