Why are the results from conv2d and multiplication in Fourier Domain not the same?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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'
I understand there's rounding errors in each operation, but which operation should I trust?
3 comentarios
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.
Respuestas (1)
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
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!