3

enter image description hereenter image description hereenter image description hereThe question is a bit broad.

Here is what I have done:

I have a method for applying the fft. I'm not going to post it because whether it is correct or incorrect is not really the point here.

I run an image through the method and then try to display what comes out as two images of the sames size, one for the real part and one for the imaginary part.

This seems to work fine except that the grayscale values that come out of my method are usually much larger than 255 and therefore I'm not sure what I'm seeing.

I then take the raw result (not whatever the pixel values I display are, since I assume they are modified somehow to fit between 0 and 255) and run it through the same method as before but with a sign change to achieve the ifft.

I then try to display this as well. Again, the raw values are much larger than 255 for the most part.

My question boils down to: a.) do i have to do some scaling on the fft to get it to fit between 0 and 255? b.) do i have to reverse this scaling when I do the ifft? c.) Is there any translation I have to do on the fft before I apply the ifft?

Part c arises from the fact that I have read some things which talk about centering the corners of the fft but I'm not really certain what this means.

A lesser question, part d, would be that if I apply the 2d fft on the original image by first applying the 1d fft to all the rows and then again to all the columns, do i need to apply the ifft in the same order or do i need to reverse the order.

I think that's all for now. I have been doing a lot of looking for answers but cant seem to find much so any help is appreciated.

EDIT: I added some images, maybe they will help. The first is the original image, the second is the result of my fft method (magnitude and imaginary component) and the third is the result of the ifft on the intermediate image.

EDIT2: Updated the images to ones from newer method.

Mason
  • 737
  • 2
  • 9
  • 23
  • Your question sounds to be one of normalization of data for display. What have you tried? – Hovercraft Full Of Eels Dec 19 '12 at 17:40
  • I guess what I really want to know is the correct procedure so I know where to fix my method. I have tried multiplying every value by 255 and dividing by the maximum value present to normalize. It didnt turn out right but like I said im not quite sure where to start troubleshooting – Mason Dec 19 '12 at 18:10
  • @Mason: I'm voting to close this question. First you asked a simple question about normalizing and plotting, which has been answered, and you now have your plots. In response you've completely changed the goal of the question so that it seems we're supposed to look at your images and debug your fft implementation. This new question is too vaguely stated and isn't really appropriate for SO either. – tom10 Dec 19 '12 at 21:06
  • Vote to close it if you want but my question is the same. All I want is answers to the same 4 questions I originally stated. I dont want anyone to debug my fft which is why I didn't post my code for that. I only posted the images to illustrate my point. The images I postes are not scaled so i wanted to get some feedback about what an unscaled image looks like. Also, the second image was meant to illustrate the translation issue since to me it looks like the quadrants might make more sense translated. Maybe next time you vote to close you should clarify first. – Mason Dec 19 '12 at 22:09

2 Answers2

3

People usually don't find it very useful to view the real and imaginary parts separately, but instead view the magnitude, and possibly the phase, but usually just the magnitude.

a) In general, yes, you will need to apply a scaling regardless of which components you're viewing. There are scaling relations between the total power of the image and it's FFT, but not the individual components. Also, you'll often want to do something like take the log of the data, or ignore the zero component, etc, so it's best just to do the scaling on your own.

b) In part a, you should do the scaling for visualizing, and don't scale the actually FFT. You should take the IFFT of the original FFT.

c) Depending on your FFT routines, you may need to divide by a factor of 2pi or the number of points in the sample, but this depends on how your FFT routines work. The docs should clarify this. As a start, just see if there's a factor of 2pi between what you start with and end with.

tom10
  • 67,082
  • 10
  • 127
  • 137
  • I think I understand what you are saying. The only reason I'm showing the imaginary part was for my own validation. I have tried everything you suggested but you did bring up an interesting question. You mentioned the magnitude. I assume you are referring to the square root of the sum of the squared components. My new question, then, is should I be applying the ifft to this magnitude or should I be applying it to the imaginary numbers themselves which I get from the fft? Also, I'm not using a library for this, I'm trying to implement it myself so there are no docs. – Mason Dec 19 '12 at 18:27
  • You should apply the IFFT to the original (imaginary) FFT data, not the magnitude. – tom10 Dec 19 '12 at 18:42
0

Answers to your four questions:

a. Do you have to scale the results of FFT to view them? Yes. You need to take magnitude then scale down to values between 0 and 255.

b. Do you have to reverse scaling before IFFT. Answer to A is only if you want to view the results of FFT. You cannot IFFT the scaled numbers. Use the original numbers.

c. Do translation between FFT and IFFT? No.

d. Does the order of Row vs Col during FFT matter? No. The results of FFT are a set of real and imaginary numbers. It is a deterministic result. You can IFFT in either order.

One of the key aspects that you may be having trouble with is the difference between the math and the visualization. The IFFT work on float or double real and imaginary numbers. The image expects integers between 0 and 255. You have to handle this conversion in code. You indicated that you thought it was "modified somehow". Safer to perform this conversion yourself.

Finally ditto on the tom10 answer. You may have to scale the results of the IFFT. It depends on the implementation of the FFT and IFFT.

Bill Johnson
  • 380
  • 2
  • 10