2
$\begingroup$

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

$\endgroup$

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ thanks. it helped a lot. $\endgroup$
    – happyman
    Commented Nov 29, 2022 at 1:58

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.