Calculate Otsu's Global threshold value
level = imgraythresh (I)
Source Image
Otsu's threshold value
The function uses Otsu's method, which chooses the threshold to minimize the intraclass variance of the black and white pixels.
S = imread(fullpath(getIPCVpath() + "/images/three_objects.png")); th = imgraythresh(S); S2 = im2bw(S,th); figure(); imshow(S2);