OpenCV-阈值

阈值:图像分割的标尺

阈值的类型

**

  • 阈值二值化(threshold binary)
    高于阈值的部分取最大值,低于阈值部分取0;
    在这里插入图片描述

  • 阈值反二值化(threshold binary Inverted)
    高于阈值的部分取0,低于阈值部分取最大值;
    在这里插入图片描述

  • 截断(truncate)
    高于阈值的部分取阈值,低于阈值部分不变;
    在这里插入图片描述

  • 阈值取零 (threshold to zero)
    高于阈值的部分不变,低于阈值部分取0;
    在这里插入图片描述

  • 阈值反取零 (threshold to zero Inverted)
    高于阈值的部分取0,低于阈值部分取不变;
    在这里插入图片描述

**
在这里插入图片描述

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

using namespace cv;
using namespace std;


Mat src, dst, gray_src;
int threshold_value = 127;
int threshold_max = 255;
int type_value = 2;
int type_max = 4;
const char* output_title = "OUTPUT";

void threshold_Demo(int, void*);
int main(int argc, char ** argv)
{
	src = imread("E://VS-pro//images//3.jpg");
	imshow("原图", src);
	namedWindow(output_title, WINDOW_AUTOSIZE);
	
	//控制阈值大小
	createTrackbar("threshold value:", output_title, &threshold_value, threshold_max, threshold_Demo );
	//控制阈值类型
	createTrackbar("type value:", output_title, &type_value, type_max, threshold_Demo);

	threshold_Demo(0, 0);
	waitKey(0);
	return 0;
}

void threshold_Demo(int, void*)
{
	cvtColor(src, gray_src,COLOR_BGR2GRAY);
	imshow("灰度图", gray_src);
	threshold(gray_src, dst, threshold_value, threshold_max, type_value);
	imshow(output_title, dst);
}

在这里插入图片描述在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值