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

1 回表示 (過去 30 日間)
OJ27
OJ27 2019 年 10 月 23 日
コメント済み: Rik 2019 年 10 月 29 日
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 件のコメント
OJ27
OJ27 2019 年 10 月 29 日
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 2019 年 10 月 29 日
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.

サインインしてコメントする。

回答 (1 件)

Dinesh Yadav
Dinesh Yadav 2019 年 10 月 29 日
編集済み: Dinesh Yadav 2019 年 10 月 29 日
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 件のコメント
OJ27
OJ27 2019 年 10 月 29 日
編集済み: OJ27 2019 年 10 月 29 日
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?

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by