一、图像阈值(threshold)

1、阈值二值化 THRESH_BINARY

2、阈值反二值化 THRESH_BINARY_INV

3、截断 THRESH_

4、阈值取0 TH_HRESTOZERO


5、阈值反取0 TH_HRESTOZERO_INV


二、
#include<opencv2/opencv.hpp>
#include<highgui.h>
#include<iostream>
using namespace cv;
Mat img,gray_img,output_img;
int threshold_vlaue=127;
int threshold_max=255;
int type_vlaue=0;
int type_max=4;
void Threshold_Demo(int,void*);
int main(int argc,char**argv)
{
Mat img=imread("1.jpg");
namedWindow("my picture",CV_WINDOW_AUTOSIZE);
namedWindow("threshold_img",CV_WINDOW_AUTOSIZE);
imshow("my picture",img);
cvtColor(img,gray_img,CV_BGR2GRAY);
createTrackbar("threshold","threshold_img",&threshold_vlaue,threshold_max,Threshold_Demo); //学会createTrackbar的使用
createTrackbar("type vlaue","threshold_img",&type_vlaue,type_max,Threshold_Demo);
Threshold_Demo(0,0);
waitKey(0);
return(0);
}
void Threshold_Demo(int,void*){
threshold(gray_img,output_img,threshold_vlaue,threshold_max,type_vlaue );
imshow("threshold_img",output_img);
}
本文通过一个具体的示例介绍了如何使用 OpenCV 实现图像阈值处理,并演示了五种不同的阈值方法:阈值二值化、阈值反二值化、截断、阈值取0及阈值反取0。通过创建滑动条调整阈值和类型,实现了直观的交互效果。
6218

被折叠的 条评论
为什么被折叠?



