1
votes

I have computed the Fourier transform of an 256-color-value grayscale image, but I'm not sure how to represent the output in a visible format.

This matrix represents the original image:

0   127 127 195
0   255 255 195

While this matrix represents the Fourier transform of the image:

1154 + 0j   -382 + 8j   -390 + 0j   -382 - 8j
-256 + 0j    128 + 128j    0 + 0j    128 - 128j

From what I know, the magnitude can be computed as sqrt((r)^2+(i)^2) where r is the real component and i is the imaginary component. However, this yields values outside of the range that can be represented in 8 bits. How do I correct this?

2
There's no "correction" to be made and there's no reason to think that the FFT values should be bounded by the input array. If you need to modify it so you can plot it, then just scale the magnitude appropriately, for example, f /= 256*f/max(abs(f)), or something similar to that. - tom10

2 Answers

1
votes

Typically, one takes the log magnitude of each complex fft result value (ignoring ones with magnitude zero), and then scale the result so that the maximum expected result is 255 (the scale factor will depend on the dimensions and input gain of the 2D image).

0
votes

Since the dynamic range of the spectrum is quite different from that of the original spatial signal, it is much difficult to use the original 8-bit format. You can use log(1+x) to shrink the range, and then scale into the 8-bit range.