Why are the results from conv2d and multiplication in Fourier Domain not the same?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
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
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!