MATLAB: Is there an alternative of thresholding an image automatically rather than setting it manually

thresholding

actually i am trying to implement a code that identifies just the round objects from an image referring http://www.mathworks.com/products/image/demos.html?file=/products/demos/shipping/images/ipexroundness.html , but the problem is that, every time for a new picture i have to change pixel value and threshold so that round objects are only visible and successfully identifies round objects rather than missing any… any alternative? or any guidence??

Best Answer

Actually function im2bw automatic select threshold value if
you do not pass any parameter except the input image.
Or try another option,, you can use graythresh if you consider not to setting the threshold value manually.
Eq:
J = im2bw(I, graythresh(I));