Opencv cvThreshould 函数

/* Types of thresholding */ #define CV_THRESH_BINARY      0  /* value = value > threshold ? max_value : 0       */ #define CV_THRESH_BINARY_INV  1  /* value = value > threshold ? 0 : max_value       */ #define CV_THRESH_TRUNC       2  /* value = value > threshold ? threshold : value   */ #define CV_THRESH_TOZERO      3  /* value = value > threshold ? value : 0           */ #define CV_THRESH_TOZERO_INV  4  /* value = value > threshold ? 0 : value           */ #define CV_THRESH_MASK        7   #define CV_THRESH_OTSU        8  /* use Otsu algorithm to choose the optimal threshold value;                                     combine the flag with one of the above CV_THRESH_* values */   /* Applies fixed-level threshold to grayscale image.    This is a basic operation applied before retrieving contours */ CVAPI(double)  cvThreshold( const CvArr*  src, CvArr*  dst,                             double  threshold, double  max_value,                             int threshold_type );


#include "stdafx.h" #include <cv.h> #include <highgui.h> #include <iostream> #include <stdio.h> using namespace std;   void sum_rgb( IplImage* src, IplImage* dst );  int main(int argc, char** argv) { 	cvNamedWindow( "example", 1 ); //create a window  	IplImage* src = cvLoadImage("C:\\Users\\Administrator\\Desktop\\1002.png" ); 	IplImage* dst = cvCreateImage( cvGetSize(src), src->depth, 1 );  // 	sum_rgb( src, dst );  	cvShowImage( "example", dst );  	while (1) 	{ 		if( (cvWaitKey( 10 )) == 27 ) 			break; 	}  	cvDestroyWindow( argv[1] ); 	cvReleaseImage( &src ); 	cvReleaseImage( &src );  	return 0; }  void sum_rgb( IplImage* src, IplImage* dst ) { 	//allocate individual image planes 	IplImage* r = cvCreateImage( cvGetSize( src ), IPL_DEPTH_8U, 1 ); 	IplImage* g = cvCreateImage( cvGetSize( src ), IPL_DEPTH_8U, 1 ); 	IplImage* b = cvCreateImage( cvGetSize( src ), IPL_DEPTH_8U, 1 );  	//temporary storage 	IplImage* s = cvCreateImage( cvGetSize( src ), IPL_DEPTH_8U, 1 );  	//split the image onto the color planes, signal channel 	cvSplit( src, r, g, b, NULL );//将三通道数据分别加载到各自的内存片中  	//add eaually weighted rgb values 	 /* void cvAddWeighted( const CvArr* src1, double alpha,const CvArr* src2, double beta,double gamma, CvArr* dst ); src1  第一个原数组.  alpha  第一个数组元素的权值  src2  第二个原数组  beta  第二个数组元素的权值  dst  输出数组  gamma  添加的常数项。  函数 cvAddWeighted 计算两数组的加权值的和:   dst(I)=src1(I)*alpha+src2(I)*beta+gamma 所有的数组必须的相同的类型相同的大小(或ROI大小)  */ 	cvAddWeighted( r, 1./3, g, 1./3, 0.0, s );  //add r & g 	cvAddWeighted( s, 2./3, b, 1./3, 0.0, s );  	//truncate values above 100 	cvThreshold( s, dst, 150, 100, CV_THRESH_TRUNC );//单通道的图像阈值操作  	cvReleaseImage( &r ); 	cvReleaseImage( &g ); 	cvReleaseImage( &b ); 	cvReleaseImage( &s ); } 



你可能感兴趣的:(Opencv cvThreshould 函数)