Otsu's thresholding algorithm

As we saw in previous sections, the simple thresholding algorithm applies an arbitrary global threshold value. In this case, what we need to do is experiment with different thresholding values and look at the thresholded images in order to see if the result satisfies our necessities. However, this approach can be very tedious.

One solution is to use the adaptive thresholding that OpenCV provides by means of the cv2.adapativeThreshold() function. When applying adaptive thresholding in OpenCV, there is no need to set a thresholding value, which is a good thing.

However, two parameters should be established correctly: the blockSize parameter and the C parameter. Another approach is to use Otsu's binarization algorithm, ...

Get Mastering OpenCV 4 with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.