Book Image

OpenCV Essentials

Book Image

OpenCV Essentials

Overview of this book

Table of Contents (15 chapters)
OpenCV Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Thresholding


Thresholding is one of the simplest yet most useful segmentation operations. We can safely say that you will end up using some sort of thresholding in almost any image-processing application. We consider it a segmentation operation since it partitions an image into two regions, typically, an object and its background. In OpenCV, thresholding is performed with the function double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type).

The first two parameters are the input and output images, respectively. The third input parameter is the threshold chosen. The meaning of maxval is controlled by the type of thresholding we want to perform. The following table shows the operation performed for each type:

Type

dst(x,y)

THRESH_BINARY

maxval if src(x,y) is greater than thresh and 0 if otherwise

THRESH_BINARY_INV

0 if src(x,y) is greater than thresh and maxval if otherwise

THRESH_TRUNC

thresh if src(x,y) is greater than thresh and src(x,y)...