Threshold functions:
Double Cvthreshold (constcvarr* src, cvarr* DST, double threshold, double max_value,int threshold_type)
Parameters:
src – original array (single channel, 8-bit of 32-bit floating point number).
DST – The output array must be the same as the SRC type, or 8-bit.
thresh – threshold value.
Max_value – Use the maximum value of cv_thresh_binary and CV_THRESH_BINARY_INV.
Threshold_type – The method that takes the threshold value for the image.
Threshold_type=cv_thresh_binary:
DST (x, y) = Max_value, ifsrc (x, y) >threshold
0, otherwise.
Threshold_type=CV_THRESH_BINARY_INV:
DST (x, y) = 0, ifsrc (x, y) >threshold;
DST (x, y) = Max_value, otherwise.
Threshold_type=cv_thresh_trunc:
DST (x, y) = threshold, ifsrc (x, y) >threshold;
DST (x, y) = src (x, y), otherwise.
Threshold_type=Cv_thresh_tozero:
DST (x, y) = src (x, y), if (x, y) >threshold;
DST (x, y) = 0, otherwise.
Threshold_type=CV_THRESH_TOZERO_INV:
DST (x, y) = 0, ifsrc (x, y) >threshold;
DST (x, y) = src (x, y), otherwise.
Threshold_type can use Cv_thresh_otsu type so that the function will use the big law OTSU The resulting global adaptive thresholds for binary images, while the parameters in the Threshold no longer works.
such as: Cvthreshold (workimg,workimg,0, 255, cv_thresh_otsu| Cv_thresh_binary)
Adaptive threshold Function:
Voidcvadaptivethreshold (const cvarr* SRC, cvarr* DST, double max_value, intadaptive_method=cv_adaptive_thresh_ Mean_c, intthreshold_type=cv_thresh_binary, int block_size=3, double param1=5);
voidcvadaptivethreshold (const cvarr* SRC, cvarr* DST, double max_value,
Intadaptive_method=cv_adaptive_thresh_mean_c,
Intthreshold_type=cv_thresh_binary,
int block_size=3, double param1=5);
Parameters:
src-input image.
DST-the output image.
Max_value-Use the maximum value of cv_thresh_binary and CV_THRESH_BINARY_INV.
Adaptive_method-adaptive threshold algorithm used: Cv_adaptive_thresh_mean_c or Cv_adaptive_thresh_gaussian_c.
Threshold_type-Take threshold type: Must be Cv_thresh_binary or CV_THRESH_BINARY_INV.
block_size-the pixel neighborhood size used to calculate thresholds: 3, 5, 7, ...
param1-parameters related to the method. On methods Cv_adaptive_thresh_mean_c and Cv_adaptive_thresh_gaussian_c,
It is a constant extracted from the mean or weighted mean, although it can be a negative number.
For the method Cv_adaptive_thresh_mean_c, the mean value in the block is calculated first, and then the param1 is reduced.
For the method Cv_adaptive_thresh_gaussian_c, the weighted sum (GAUSSIAN) in the block is calculated first, and then the param1 is lost.
when block_size relatively small, the equivalent of extracting edges.
Results comparison:
The results of the thresholding are as follows:
Otsu The results are as follows:
Adaptive threshold Value The results are as follows:
OpenCV two value-cvthreshold and adaptive binary cvadaptivethreshold and Otsu