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