问题
There is an operation called Shift which is performed after DFT to bring zero-frequency components to the center of the frequency spectrum.
I have two questions regarding this operation:
- Why don't/can't DFT automatically center the zero-frequency components?
- What happens if we don't perform Shift operation after DFT? I.e. how does it affect our other tasks of image processing?
- Can anyone provide me some material to know about this specific operation named Shift?
References:
- fftw shift zero-frequency to the image center
- Why we shift the zero-frequency component to the center of the spectrum?
回答1:
The DFT, by definition, uses n=0..N-1
and k=0..N-1
, where n
is the index into the time-domain signal and k
the index into the frequency-domain signal. k
also corresponds to the frequency. The DFT is defined this way in analogy to Fourier series.
Since the frequency in the DFT is periodic, one can think of k=N-1
to correspond to k=-1
instead. The shift function thus moves the upper half of the frequencies to the left of the origin, so they can be more readily interpreted as negative frequencies. But this is solely a convenience for display, as it brings the frequency-domain signal to a form that we're more familiar with (this is probably because it makes some Fourier analysis easier to explain, and hence text books display it this way, and hence we learn about Fourier by looking at Frequency plots with the origin in the middle).
For most tasks in image processing, we do not need to shift the origin. Again, it is only for display that this is convenient and pretty.
For example, to compute cross-correlation:
cc = ifft( fft(img1) * conj(fft(img2)) )
Here, the top-left pixel of cc
is the origin. If img1==img2
, the top-left pixel will be the maximum value. If we had an fft
function that shifted the origin to the middle, then the cross-correlation image cc
would have its origin in the middle also. After finding the peak, we'd need to do some computations to figure out what the shift between img1
and img2
is. (Not that this is complicated, but it shows that shifting is not necessarily advantageous.)
When convolving, one often has a spatial-domain kernel with the origin in the middle (as for example in this recent question). In this case, one must shift the origin to the top-left before computing the DFT. But there is no point in shifting the origin of the frequency-domain signals just to multiply them together and then undo the shift. One can simply directly multiply the signals that have the origin in the top-left corner:
kernel = ifftshift(kernel)
filtered = ifft( fft(img) * fft(kernel) )
Note that there are two different shift functions, often called fftshift
and ifftshift
. The one shifts the origin from the top-left to the middle, the other shifts the origin from the middle to the top-left. These two functions do exactly the same thing for even-sized signals (images), but differ if the sizes are odd.
来源:https://stackoverflow.com/questions/51204565/why-doesnt-fft-automatically-produce-a-zero-frequency-centered-output