Objective
In the previous article, we explained the changes in brightness and contrast in image processing, and this article we'll do a threshold function.
The simplest method of image segmentation
The threshold is the simplest method of image segmentation.
For example, in order to separate the apples from the image below, we use the gray difference between the foreground and the background, by setting a threshold value, which is black when the pixel is greater than this threshold, and is less than gray.
Five types of threshold values
As with OPENCV, we will provide five types of thresholds for ease of use.
The following is the waveform representation of the original image, the ordinate indicates the pixel gray value size, the Blue line is the threshold size.
Binary threshold value
The formula representation is:
TEXTTT{DST} (x,y) = Fork{texttt{maxval}}{if $texttt {src} (x,y) > Texttt{thresh}$}{0}{otherwise}
The image representation is:
Threshold Binary
The maximum value (that is, 255) that exceeds this threshold is visible, otherwise the minimum value (that is, 0) is changed. We need a function to implement this function:
var cv_thresh_binary = function (__value, __thresh, __maxval) {return
__value > __thresh? __maxval:0;
};