How to implement fft2 and ifft2 to this convolution problem to get a real value velocity

3 vues (au cours des 30 derniers jours)
I'm doing a problem on image segmantation using one active contour method, but I can not get a real value velocity to implement a later Hamilton-Jacobi dynamic equation. HERE is the paper I am trying to reproduce and a code with problems. I mainly want to know what is wrong about my velocity function which is calculated using the fast fourier transform as introduced in the section 4.1 of the paper.

Réponses (1)

Walter Roberson
Walter Roberson le 23 Avr 2020
The function ActiveContour constructs a symmetric object centered around (128,128) . Then it calculates the curvature of that object. The gradient of it is calculated, and since everything is symmetric around the center, the gradient at (128,128) is 0. But the calculation of the curvature involves dividing by the gradient, so that involves a division by 0. When you have a division by 0, if the numerator is non-zero then the result is infinity times the sign of the numerator, and if the numerator is also 0 then the result is nan. The numerator happens to be non-zero at (128,128) so you get an infinite value. You have two of those divisions by 0 in the same expression, and the infinities that are produced happen to be opposite sign, so you get infinity - infinity which gives nan. Therefore at one point, (128,128), the curvature returned is nan. That results in a phi that is nan at one point.
Then in the next iteration of the for loop, that phi is used for further computations, and the nan "poisons" those computations, leading to more and more nans.
Work-around: after you calculate C in curvature(),
C(isnan(C)) = 0;
  1 commentaire
Jialin Zeng
Jialin Zeng le 23 Avr 2020
Thanks a lot for correcting! I understand that gradient is 0, but do you mean duxc2 and duyc2 have opposite signs?I think they are of same signs. Anyway, I tried to fix it by adding a small eps to the gradient so that Nans didn't appear anymore. Is that a good fix? In addition, the same problem as this title is still unsettled, because according to the paper, the ifft2 of V should be a real matrix,but in my velocity function, ifft2 of V is complex,which makes it hard to carry on the later H-J equation. I just take the real part of V as V but it makes the result undesirable, so I think there must be some problems in this function. Perhaps my understanding of this implementation is totally wrong. I just can't think of which part goes wrong leading to this complex velocity.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by