<LearnOpenCV(12) C++>二值图像阈值操作

图像阈值

简单了解图像阈值操作

二值化 THRESH_BINARY

大于阈值的赋值255,小于阈值的赋值0

反二值化 THRESH_BINARY_INV

小于阈值的赋值255,大于阈值的赋值0

截断 THRESH_TRUNC

大于阈值的等于阈值,小于阈值的不变

阈值取零 THRESH_TOZERO

大于阈值的不变,小于阈值的赋值0

阈值反取零 THRESH_TOZERO_INV

大于阈值的赋值0,小于阈值的不变

自动阈值

THRESH_OTSU 待细究

THRESH_TRIANGLE 待细究

代码

在这里插入图片描述

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

Mat src, gray_src, dst;
int threshold_value = 127;
int threshold_max = 255;
int loc = 0;
int i[5] = { 0,1,2,3,4 };//几种阈值处理的对应编码是 0-4,具体可以看源码的枚举。
void Threshold_d(int, void*);
int main()
{
	

	src = imread("girl6.jpg");
	if (!src.data)
	{
		printf("Wrong with Loading img!\n");
		return -1;
	}

	namedWindow("out", WINDOW_AUTOSIZE);
	createTrackbar("Threshold", "out", &threshold_value,  threshold_max, Threshold_d);
	createTrackbar("Type", "out", &loc	, 4, Threshold_d);

	waitKey(0);
	return -1;
}
void Threshold_d(int, void*)
{
	cvtColor(src, gray_src, COLOR_BGR2GRAY);//8位单通道灰度图像 CV_8UC1

	threshold(gray_src, dst, threshold_value, threshold_max, i[loc]);

	imshow("out", dst);
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wdmcs

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值