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)


1 Answer 1


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

  • 1
    $\begingroup$ in other words, shifting the image half the image size on each axis, and wrapping is in fact the way you do it, but if then doing ifft, you have to take care to undo the shift without an off by one error. Thanks! $\endgroup$
    – Alan Wolfe
    Jul 28, 2016 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.