# Before the fft2, why need fftshift for the kernel?

When I study some paper, I have some questions about usase of convolution theorem.

Laplacian  = [0 1 0;1 -4 1;0 1 0];
F = padarray(Laplacian,[m-3+1,n-3+1]/2,'pre');
F = padarray(W,[m-3-1,n-3-1]/2,'post');


F : filter

From this, first I want use convolution theorem :

fft2(image).*fft2(F).


But, in the reference, the method is used like :

fft2(image).*fft2(fftshift(F)).


What am I doing wrong? Thanks

## 1 Answer

For the FFT, the origin is in the top-left corner, not in the middle of the image.

If you create a kernel and pad it such that the origin is in the middle of the image, then compute the FFT, you will have the FFT of a shifted kernel. Applying this will shift your result image too.

You need to use ifftshift, not fftshift, to shift the kernel’s origin to the top-left pixel. fftshift shifts the origin from the top-left back to the middle. The two functions produce the same result on an even-sized image, but not on an odd-sized one.

• thanks. it helped a lot. Nov 29, 2022 at 1:58