Why are the results from conv2d and multiplication in Fourier Domain not the same?

2 visualizaciones (últimos 30 días)
I want to convolve two images of the same size. One of them is the input image and the second is the linear representation of the system, PSF.
We can either convolve
y = conv2(x,PSF,'same');
or convert each image to the frequency domain, find the product, and find the inverse transform.
X=fft2(x);
OTF= psf2otf(PSF,size(PSF));
Y = OTF.*X;
y = real(ifftn(Y));
However, when I take a look at the output of each operation there's a sginificant difference. Below, you can see the comparisson of the two outputs using imshowpair with the option 'diff'
outputdiff.jpg
I understand there's rounding errors in each operation, but which operation should I trust?
  3 comentarios
OJ27
OJ27 el 29 de Oct. de 2019
Thank you for your reply. I have not tried that so far. However, my goal is to generalize my code to larger images, this image was used as a test to see what's going on. Nested loops will increase the computational time so I am torn to code my own convolution code.
Rik
Rik el 29 de Oct. de 2019
I didn't mean you should be using that code on your actual full size image, only to test which of the two methods is most similar to what you would code with loops.
Because of the 4 nested loops the computation time will rapidly make it not feasible. (I remember some process would have taken 100 years to complete for my nested loops, while only taking about a minute with convolutions, so I'm fully aware that nested loops are only for testing really basic images).
Your difference image looks like it is mostly 2 or 3 edge pixels that are causing a large difference.

Iniciar sesión para comentar.

Respuestas (1)

Dinesh Yadav
Dinesh Yadav el 29 de Oct. de 2019
Editada: Dinesh Yadav el 29 de Oct. de 2019
conv2 will have negligible rounding off errors as compared to taking fft then taking ifftn and taking real part. Simply because of the fact that while taking fft we often have a complex part but while converting back you are only taking the real part in final output. The information contained in complex part is completely lost.
  1 comentario
OJ27
OJ27 el 29 de Oct. de 2019
Editada: OJ27 el 29 de Oct. de 2019
But even if I remove the real command the resulting image still differs. Actually when I run isreal(ifft(Y)), it tells me that the resulting image is purely real. Does ifft remove the phase component?

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by