Need help with FFT2

13 views (last 30 days)
Sam
Sam on 7 Feb 2013
I have an image that I am trying to do a 2D FFT on. The issue I'm having is that when I do the transformation, I get numbers which are extremely large and won't display correctly when I try to show the transform.
For example, I can read in a jpg or a png with nothing unusual about it, all numbers between 0 and 255. When I perform the transform, however, I get numbers on the order of 1E7, which is too large to be plotted without some adjustments. I have looked at some sample code online, and no one else seems to have to correct for the transform producing numbers which are too large.
Does anyone have any tips or information on how to correctly perform and FFT2, or let me know if I have to do a constant scaling factor on all of my FFTs, or any other sort of information?

Answers (3)

Walter Roberson
Walter Roberson on 7 Feb 2013
I suspect that if you check, it will be one single location that has those large values: the location corresponding to the DC offset, which in turn corresponds to the average value of the data.
If you were to use im2double() on the image and then subtract off mean2() of the that, the result should have 0 for that average.
  4 Comments
Image Analyst
Image Analyst on 7 Feb 2013
I usually take the log of the spectrum before displaying it because usually the DC spike is so tall that it suppresses all the other stuff, which is the more interesting stuff that you want to see. Taking the log lets you see all of it fairly well. Sam, I have a demo if you want where I demonstrate that.
Sam
Sam on 8 Feb 2013
Image Analyst, if you don't mind, I would like to see the demonstration.

Sign in to comment.


Youssef  Khmou
Youssef Khmou on 7 Feb 2013
Edited: Youssef Khmou on 7 Feb 2013
Hi, as others mentioned above , when you perform the FFT2, the first element F(1,1) contains the sum of all elements of the 2d input signal, and you should use the abs, abs² or 10 (20) log10( abs) ,
The only thing i can tell you is that you can per example use the 2D AUTOCORRELATION FUNCTION, that you can use to even study the 2D AWGN .
I made a small tutorial (pdf file) on my submission about the 2D Autocorrelation function which actionly uses fftshift, fft2 and ifft 2 :
i hope that helps

Youssef  Khmou
Youssef Khmou on 8 Feb 2013
hi Sam,
In your question you said that you apply the transformation on png or jpg sample with numbers between 0 255, so its obviously uint8 class, but when you apply fft2 you get a warning :
Warning: FFTN on values of class UINT8 is obsolete.
Use FFTN(DOUBLE(X)) or FFTN(SINGLE(X)) instead.
Here is an example of one way i use fft2 :
% First example
I=imread('circuit.tif');
FI=fft2(double(I));
surf(10*log10(abs(fftshift(FI))))
figure, imagesc(10*log10(abs(fftshift(FI))));
If you are concerned with large values, you can normalize you result :
FI=FI/max(FI(:));

Categories

Find more on Image Processing Toolbox 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!