Adaptive thresholding

Applying a threshold on an image in order to create a binary image could be a good way to extract the meaningful elements of an image. Suppose that you have the following image of a book:

Since you are interested in analyzing the text in this image, you apply a threshold to this image, as follows:

  // using a fixed threshold  
  cv::Mat binaryFixed; 
  cv::threshold(image,binaryFixed,70,255,cv::THRESH_BINARY); 

You obtain the following result:

In fact, no matter what value you choose for the threshold, in some parts of the image, ...

Get OpenCV 4 Computer Vision Application Programming Cookbook - Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.