Extracting Spatial frequency from fourier transform (fft2 on Images)
72 views (last 30 days)
Show older comments
Steps:
1. fft2 on the Image 2. Extracting Spatial frequency (in Pixels/degree) 3. Plotting magnitude of the fourier transform (power spectral density of the image) Vs Spatial frequency
Now, for step 2 - Rick Rosson's answer on this question might give some directions. http://www.mathworks.com/matlabcentral/answers/13896
But, for step 3 - I have to be able to relate the magnitude of the fourier transform with the corresponding spatial frequencies, to plot them. I am not clear how to extract this correlation from the MATLAB fft2 output. Any help would be appreciated.
PS: For people interested in the Optics part of it, I am trying to plot the Modulation Transfer Function (Figure 7 in the link below). The method is outlined here: http://maxwell.uncc.edu/gboreman/publications/Daniels_OE_4_1995.pdf
0 Comments
Answers (3)
Wayne King
on 23 Oct 2013
Edited: Wayne King
on 23 Oct 2013
If you have a simple 2-D complex exponential
x = 0:159;
y = 0:159;
[X,Y] = meshgrid(x,y);
Z = exp(1i*pi/4*(X+Y));
Z = real(Z);
imagesc(Z);
Then note that with a matrix of 160x160, we would expect pi/4 to be shifted from the center (80,80) to (101,101) and (61,61) (if you are using fftshift to move (0,0) to the center of the image)
Zdft = fftshift(fft2(Z));
imagesc(abs(Zdft))
Zdft(101,101)
Zdft(61,61)
Note they are complex conjugates of each other as expected.
On a matrix 160x160, each step will move you (2*pi)/160 radians/(unit length) in angular spatial frequency, so that's why find pi/4 essentially 20 pixels away from the center of the image (0,0).
0 Comments
Mona Mahboob Kanafi
on 23 Oct 2013
If I get it right, you need a 2D graph of power spectral density versus frequencies. When you do a 2D fft on an image, you get a 2D matrix in matlab representing the fourier transform of your image. You then just need to assign fx and fy in order to plot the 3D graph of FFT. Now, to get power spectral density :
PSD = (a^2/n*m)*(abs(FFT))
where a is pixel width and n & m are number of pixels in each direction.
With this, you obtain the PSD. Now you again obtain a 3D graph of PSD versus fx and fy, But what you want is a 2D graph of PSD-f!
Here it depends on your system. If the system is isotropic then I would do a radial averaging over the 2D FFT which gives me a 2D graph of PSD-fr. Or if it isn't, then I wouldn't use ff2. Instead, I would use fft over parallel lines in the direction I want(say x) and averaged them together in order to obtain a 2D PSD versus fx!
Mona Mahboob Kanafi
on 23 Oct 2013
Edited: Mona Mahboob Kanafi
on 24 Oct 2013
qx_1=zeros(m,1);
for k=0:m-1
qx_1(k+1)=(2*pi/m)*(k);
end
qx_2 = fftshift(qx_1);
% for removing discontinuity in the middle, shift data by 2pi
qx_3 = unwrap(qx_2-2*pi);
qx=qx_3/a;
qy_1=zeros(n,1);
for k=0:n-1
qy_1(k+1)=(2*pi/n)*(k);
end
qy_2 = fftshift(qy_1);
qy_3 = unwrap(qy_2-2*pi);
qy=qy_3/a;
I understood this by reading steve's blog on this frequency assignment, you can also refer to that:
Just one more hint for you, I believe averaging row data on fft2 does not give you correct result. Just take a look at a 2D fft graph that has been centralized by fftshift. Or at least in my case it doesn't give correct results, so I suggest the methods I explained above.
good luck
2 Comments
Mona Mahboob Kanafi
on 24 Oct 2013
Edited: Mona Mahboob Kanafi
on 24 Oct 2013
Sorry, nn and mm are n and m, I fixed them above. after fixing this, what you get is two matrices, one of them 1*1280 and the other one 1*720. The maximum frequency in both fx and fy are the same, because maximum frequency is related to the minimum wavelength and that is pixel width(fmin = 1/a), but according to Nyquist frequency, the maximum f can't exceed 1/2a! To sum up, your maximum f are always 1/2a (or 2pi/2a if you want to work with wavevector rather than frequency).
You minimum f is related to maximum available wavelength in you system which is size of your image in each direction, so min fx is different from min fy. i.e. fyMax = 1/a*n & fxMax =1/a*m
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!