Threshold value:
Main function: Threshold
Code:
1#include <opencv2\opencv.hpp>2#include <iostream>3#include <string>4 5 #pragmaComment (linker, "/subsystem:\" windows\ "/entry:\" Maincrtstartup\ "")6 7 intMax_kernel_length = to;8 9 using namespacestd;Ten using namespaceCV; One A voidShow (ConstSTD::string&name,ConstMat &img) - { - Namedwindow (name, cv_window_autosize); the imshow (Name, IMG); - } - - intMainvoid) + { -Mat img = Imread ("lena.jpg"); + if(Img.empty ()) A return-1; at - Mat Gray; - //convert img to Gray image - Cvtcolor (img, Gray, Cv_rgb2gray); -Show ("Source", gray); - /*0:binary in 1:binary Inverted - 2:threshold truncated to 3:threshold to Zero + 4:threshold to Zero inverted - */ the Mat DST; * intValues = -; $Threshold (gray, DST, values,255, cv_thresh_binary);Panax NotoginsengShow ("Dst", DST); - Waitkey (); the return 0; +}
The comment section describes the meaning of the threshold transformation represented by the third parameter of the function:
0: Two value
1: Reverse Binary Value
2: Truncate
3. Reset Zero
4. Low Zero
The results of the above 0 parameters are:
Explain:
Binary will set all pixels above the threshold values to the maximum 255 (black) maxval parameter, while the other values less than the threshold value are 0 (white).
Reference formula:
The following are the results of several other parameters:
1:binary, inverted
The formula is as follows:
2.Truncate
Formula:
3.Threshold to Zero
Formula:
4.Threshold to Zero, inverted
Formula:
Note: The above code is all the same as the example, the difference is that the last type parameter of the threshold is changed, provided as follows:
1 cv_thresh_binary; 2 CV_THRESH_BINARY_INV; 3 Cv_thresh_trunc; 4 Cv_thresh_tozero; 5 Cv_thresh_tozero_inv;
The meaning is literally, and the specific use of self-groping. Because it is said that the threshold in the image segmentation role is relatively large, it is recommended to focus on memory and experience.
Add the above threshold transformation diagram, the first line is the original waveform, the Blue line is the threshold line, the remaining lines of the graph corresponding to the top row of the above five kinds of threshold transformation of the results, according to the above order:
Above.
OPENCV Official Document Learning record (11)