Another automatic thresholding algorithm is the triangle algorithm, which is considered a shape-based method because it analyzes the structure (or shape) of the histogram (for example, trying to find valleys, peaks, and other shape histogram features). This algorithm works in three steps. In the first step, a line is calculated between the maximum of the histogram at bmax on the gray level axis and the lowest value bmin on the gray level axis. In the second step, the distance from the line (calculated in the first step) to the histogram for all the values of b [bmin-bmax] is calculated. Finally, in the third step, the level where the distance between the histogram and the line is maximal is chosen as the threshold value.
The way to use the triangle binarization algorithm in OpenCV is very similar to Otsu's algorithm. In fact, only one...