Otsu's method estimates the threshold for grayscale images in such a way that after binarization and converting the original image to a binary mask, the total intra-class variance for two classes is minimal. Otsu's method can be used with the help of the cv2.threshold function, having specified the flag cv2.THRESH_OTSU.
The following output is expected from the preceding code:
Estimated threshold (Otsu): 116.0