编号 | 阈值类型枚举 |
注意
|
1 | THRESH_BINARY |
|
2 | THRESH_BINARY_INV |
|
3 | THRESH_TRUNC |
|
4 | THRESH_TOZERO |
|
5 | THRESH_TOZERO_INV |
|
6 | THRESH_MASK |
不支持
|
7 | THRESH_OTSU |
不支持32位
|
8 | THRESH_TRIANGLE |
不支持32位
|
Mat gray;
cvtColor(src, gray, CV_BGR2GRAY);
// 全局二值化
int th = 100;
cv::Mat threshold1,threshold2,threshold3,threshold4,threshold5,threshold6,threshold7,threshold8;
cv::threshold(gray, threshold1, th, 255, THRESH_BINARY);
cv::threshold(gray, threshold2, th, 255, THRESH_BINARY_INV);
cv::threshold(gray, threshold3, th, 255, THRESH_TRUNC);
cv::threshold(gray, threshold4, th, 255, THRESH_TOZERO);
cv::threshold(gray, threshold5, th, 255, THRESH_TOZERO_INV);
//cv::threshold(gray, threshold6, th, 255, THRESH_MASK);
cv::threshold(gray, threshold7, th, 255, THRESH_OTSU);
cv::threshold(gray, threshold8, th, 255, THRESH_TRIANGLE);
cv::imshow("THRESH_BINARY", threshold1);
cv::imshow("THRESH_BINARY_INV", threshold2);
cv::imshow("THRESH_TRUNC", threshold3);
cv::imshow("THRESH_TOZERO", threshold4);
cv::imshow("THRESH_TOZERO_INV", threshold5);
//cv::imshow("THRESH_MASK", threshold6);
cv::imshow("THRESH_OTSU", threshold7);
cv::imshow("THRESH_TRIANGLE", threshold8);
cv::waitKey(0);
|
原图
|
|
THRESH_BINARY
|
|
THRESH_BINARY_INV
|
|
THRESH_TRUNC
|
|
THRESH_TOZERO
|
|
THRESH_TOZERO_INV
|
|
THRESH_OTSU
|
|
THRESH_TRIANGLE
|