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 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.