图像形态学 - 自适应阈值(cvAdaptiveThreshold)
来源:互联网 发布:防范网络诈骗心得800 编辑:程序博客网 时间:2024/06/06 01:49
自适应阈值:
是一种改进了的阈值技术,其中阈值本身是一个变量,自适应阈值T(x,y)的每个像素点都不同,通过计算像素点周围的b*b区域的加权平均,然后减去一个常数来得到自适应阈值。
cvAdaptiveThreshold方法:
Provides adaptive thresholding binary image.
void cvAdaptiveThreshold( IplImage* src, IplImage* dst, double max,
CvAdaptiveThreshMethod method, CvThreshType type, double* parameters);
src Source image.
dst Destination image.
max Max parameter, used with the types CV_THRESH_BINARY and CV_THRESH_BINARY_INV only.
method Method for the adaptive threshold definition; now CV_STDDEF_ADAPTIVE_THRESH only.
type Thresholding type; must be one of
• CV_THRESH_BINARY,
• CV_THRESH_BINARY_INV,
• CV_THRESH_TOZERO,
• CV_THRESH_TOZERO_INV,
parameters Pointer to the list of method-specific input parameters. For the method CV_STDDEF_ADAPTIVE_THRESH the value parameters[0] is the size of the neighborhood: 1-(3x3), 2-(5x5), or 3-(7x7), and parameters[1] is the value of the minimum variance.
#include <highgui.h>#include <math.h>#include <cv.h>IplImage *Igray = 0, *It = 0, *Iat;int main( int argc, char** argv ){if( argc != 7 ){return -1;}//输入命令行double threshold = (double)atof( argv[1] ); //convert string to doubleint threshold_type = atoi( argv[2] ) ? CV_THRESH_BINARY : CV_THRESH_BINARY_INV;int adaptive_method = atoi( argv[3] ) ? CV_ADAPTIVE_THRESH_MEAN_C : CV_ADAPTIVE_THRESH_GAUSSIAN_C;int block_size = atoi( argv[4] );double offset = (double)atof( argv[5] );//加载灰度图if( ( Igray = cvLoadImage( argv[6], CV_LOAD_IMAGE_GRAYSCALE ) ) == 0 ){return -1;}//创建同样大小8位灰度图用于输出It = cvCreateImage( cvSize( Igray -> width, Igray -> height ), IPL_DEPTH_8U, 1 ); //单通道8位灰度图Iat = cvCreateImage( cvSize( Igray -> width, Igray -> height ), IPL_DEPTH_8U, 1 );//阈值化cvThreshold( Igray, It, threshold, 255, threshold_type );cvAdaptiveThreshold( Igray, Iat, 255, adaptive_method, threshold_type, block_size, offset );//命名窗体输出cvNamedWindow( "Raw", 1 );cvNamedWindow( "Threshold", 1 );cvNamedWindow( "Adaptive Threshold", 1 );cvShowImage( "Raw", Igray );cvShowImage( "Threshold", It );cvShowImage( "Adaptive Threshold", Iat );cvWaitKey(0);//回收内存cvReleaseImage( &Igray );cvReleaseImage( &It );cvReleaseImage( &Iat );cvDestroyWindow( "Raw" );cvDestroyWindow( "Threshold" );cvDestroyWindow( "Adaptive Threshold" );return 0;}
/*input*/
在cmd debug目录下输入chapter_5_example_4.exe 15 1 1 71 15 fruits.jpg
其中:
【0】=chapter_5_example_4.ex
【1】=15,Threshold
【2】=1,Type
【3】=1,Method
【4】=71,Block Size
【5】=15,Offset
【6】=原始图像名
/*result*/
raw gray image
cvThreshold处理
cvAdaptiveThreshold处理
结论,自适应阈值效果比较好,可以自动找到图像特征目标的轮廓。
转自:http://blog.csdn.net/hitwengqi/article/details/6856768
- 图像形态学 - 自适应阈值(cvAdaptiveThreshold)
- 第五章 - 图像形态学 - 自适应阈值(cvAdaptiveThreshold)
- 自适应阈值 cvAdaptiveThreshold
- Learning OpenCV cvAdaptiveThreshold 自适应阈值
- 局部自适应阈值二值化cvAdaptiveThreshold
- Learning OpenCV cvAdaptiveThreshold 自适应阈值
- OpenCV 阈值化操作cvThreshold 和 自适应阈值cvAdaptiveThreshold操作
- opencv学习笔记(二十)自适应阈值cvAdaptiveThreshold ()
- 图像处理20:自适应阈值
- 第五章 - 图像形态学 - 阈值化(cvThreshold),通道求和
- 图像分割自适应阈值的求取
- 使用自适应形态学闭操作和本地自适应阈值的车牌检测
- 阈值化 OTSU算法 cvAdaptiveThreshold 函数
- 自适应阈值
- 自适应阈值
- OTSU方法计算图像二值化的自适应阈值
- OTSU方法计算图像二值化的自适应阈值
- OTSU方法计算图像二值化的自适应阈值
- 编程之美2.15 子数组之和的最大值(二维)
- 错误整理:RsyncServer服务无法正常启动的解决办法
- 成大事必备9种能力、9种手段、9种心态
- perl 连接sql server数据库
- C++学习书籍推荐
- 图像形态学 - 自适应阈值(cvAdaptiveThreshold)
- Unity3d---> IEnumerator
- 你需要的不是重构,而是理清业务逻辑
- 混迹在腾讯微博的知名站长名单
- 使用dbms_meadata.get_ddl获得oracle数据库对象DDL信息
- mysql密码修改
- Java初始化顺序
- 关于 Javascript 的闭包理解
- Flex嵌入字体错误