How to show Image FFT with origin as DC? The page Here explains how to do the discrete fourier transform on a 2d image.  It mentions this:


  In most implementations the Fourier image is shifted in such a way
  that the DC-value (i.e. the image mean) F(0,0) is displayed in the
  center of the image. The further away from the center an image point
  is, the higher is its corresponding frequency.


I have the implementation working, but I'm not sure how to shift my image to make DC be the center of the image.  Does anyone know how to do that?

The best I can think of is to push everything right 1/2 of width and up 1/2 of height, and wrap the pixels around, but this doesn't seem like the correct thing to do.

Does anyone know how to make this transform?  Right now, DC is in the lower left of my image, at pixel (0,0)
The quadrants of the FFT should be shifted Q1->Q3, Q2->Q4 ...
For a [RxC] matrix X this may be accomplished by shifting as:

tmpX = shift_row(    X, floor(R/2) )
Y    = shift_col( tmpX, floor(C/2) )


where shift_row and shift_col is your shift operator in each dimension and floor is the round towards zero operator.

For the inverse FFT shift you should shift in the same way but with a value -ceil(R/2) and -ceil(C/2), i.e rounded towards infinity