How can I implement auto threshold into my code rather than defining the threshold for each image?

Hi everyone. I would like to implement auto-thresholding into my Matlab code as I don't want to define manually for each image. For example, I define my threshold like; binaryImage = myinput <0.7; Is there any way to find the best threshold automatically and use that threshold for images I have.

2 件のコメント

Ameer Hamza
Ameer Hamza 2018 年 5 月 22 日
編集済み: Ameer Hamza 2018 年 5 月 22 日
It will be possible most probably. But first, you need to define best threshold. How do you measure whether a specific threshold is best or not?
engineer
engineer 2018 年 5 月 22 日
I find the best threshold by trial and error. The best threshold for me is that the background pixel is fully black (0) and the object's pixel is fully white (0).

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

 採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 22 日
See adaptthresh(). This will estimate a threshold value without the need to manually specifying it.

6 件のコメント

engineer
engineer 2018 年 5 月 22 日
I tried, but it did not give me a good result, unfortunately.
engineer
engineer 2018 年 5 月 22 日
Thank you very much, I used otsu method and it worked. However, I still have an issue. Because in my image, the object is separated from the background and its pixel is white. However, there is some non-visible white pixel on the image as well. How can I get rid of those white pixels? My calculation is based on the white pixels on the objects. Therefore, other white pixels affect my calculation in a negative way.
Ameer Hamza
Ameer Hamza 2018 年 5 月 22 日
Use bwareaopen() to remove patches of white pixels which are less than some defined pixel numbers.
engineer
engineer 2018 年 5 月 22 日
thank you very much.
Ameer Hamza
Ameer Hamza 2018 年 5 月 22 日
You are welcome.

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

その他の回答 (0 件)

質問済み:

2018 年 5 月 22 日

コメント済み:

2018 年 5 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by