Reputation: 29
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);
Upvotes: 0
Views: 2506
Reputation: 2132
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.
Upvotes: 3