Why running same code on the same image gives different result every time?
古いコメントを表示
Hi, I am running a watershed segmentation on one image, but I found it gave me different result every time when I ran the same code on the same image. Can anyone help me? Thank you.
回答 (1 件)
John D'Errico
2017 年 8 月 30 日
1 投票
Whenever this happens, it means that some piece of the algorithm involved probably required starting values, usually for a search of some kind. In that case, a random starting point is probably generated, ergo you will get potentially a slightly different result based on where the search originated. Not all such searches will always end in the same solution, if multiple solutions exist. Or the solution might be subtly different, but still within tolerances that were deemed acceptable.
While I don't claim to have looked up the specifics of the algorithm involved, I have no doubt that a varying result is due to a random start somewhere inside that algorithm.
5 件のコメント
Tian Tian
2017 年 8 月 30 日
@Tian Tian: Did you see the "{} Code" button? Select the code and press it. Afterwards your code is much easier to read and this is a good idea for posting in the forum.
The solution is easy:
J = imnoise(I0,'gaussian',0,0.025);
You add random noise to the image. Of course this can change the results randomly.
John D'Errico
2017 年 8 月 30 日
@Tian Tian - Almost at the very first line I see random noise involved. So what is surprising about a variable result?
rand('seed',0)
is not a syntax I can see documented for my Matlab (R2017a). I assume it is old syntax prior to the 'rng' function. However, it does appear to cause random numbers to be produced from the same seed each time. What happens after that though I have no idea because the code is unreadable.
Steven Lord
2017 年 8 月 30 日
カテゴリ
ヘルプ センター および File Exchange で Object Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!