020-OpenCV4(C++)二值图像概念,以及阈值化分割threshold

一、二值图像定义:

单通道,取值0与255。

二、阈值化分割:

1.五种分割方式:

020-OpenCV4(C++)二值图像概念,以及阈值化分割threshold_第1张图片

2. 五种方式对应API:

Mat gray, binary;
	cvtColor(src, gray, COLOR_BGR2GRAY);
	imshow("input", gray);
	threshold(gray, binary, 127, 255, THRESH_BINARY);
	imshow("dst1", binary);
	threshold(gray, binary, 127, 255, THRESH_BINARY_INV);
	imshow("dst2", binary);
	threshold(gray, binary, 127, 255, THRESH_TRUNC);
	imshow("dst3", binary);
	threshold(gray, binary, 127, 255, THRESH_TOZERO);
	imshow("dst4", binary);
	threshold(gray, binary, 127, 255, THRESH_TOZERO_INV);
	imshow("dst5", binary);

你可能感兴趣的:(OpenCV初级,opencv,c++)