Why doesn't FFT automatically produce a zero-frequency centered output?

蹲街弑〆低调 提交于 2019-12-11 06:52:20

问题


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:

  1. Why don't/can't DFT automatically center the zero-frequency components?
  2. What happens if we don't perform Shift operation after DFT? I.e. how does it affect our other tasks of image processing?
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!