0

How can i find orientation using fft? Here is the idea (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))

My problem is how can I implement the last step? Here is the code that I tried but could not understand the last step. Matlab code:

    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

Rijul Sudhir
  • 2,064
  • 1
  • 15
  • 19
rossy
  • 29
  • 6

1 Answers1

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)));

Now you have to create masks. Here is a reference for how mask should be. Read Frequency Orientation Page 70

Here is something to start with Pixels between 2 intersecting lines

Create a mask with same dimension as image and multiple it with P and sum the matrix. You will get the A(Theta) for that direction. If first mask is at mask(:,:,1) and if you have 4 masks (mask(:,:,1),mask(:,:,2),mask(:,:,3),mask(:,:,4)). Then rest of the code will be.

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

Now you will have A for four directions. Now you are done.

Community
  • 1
  • 1
Rijul Sudhir
  • 2,064
  • 1
  • 15
  • 19
  • I want to find the orientation .I mean i know the orientation of those line is 90 degree .I want to find that value from Fourier power spectrum. – rossy May 23 '16 at 15:01
  • What you want is a single value for orientation? – Rijul Sudhir May 23 '16 at 15:06
  • Can you please update your idea in the question in a more detailed manner. If you have any reference for your last step. Include that also. – Rijul Sudhir May 23 '16 at 15:10
  • I added the reference paper in my q.I would be grateful if you could guide me to implement the idea. – rossy May 23 '16 at 15:31
  • Thank you.I am trying to follow your idea. – rossy May 23 '16 at 17:44
  • It is better to avoid the `ur1` and `ur2` in the last equation(`A(theta)`) of your reference paper ,instead sum till the end. If you really want to do that also. Create a circular mask with inner radius ur1 and outer radius ur2 (http://stackoverflow.com/questions/30592110/circular-mask-in-matlab). Then multiply it with your current mask to get the new mask and use that mask instead. – Rijul Sudhir May 23 '16 at 17:48
  • Thank you.I am now trying to understand the mask technique. – rossy May 23 '16 at 18:52