资源描述:
《阈值化OTSU算法cvAdaptiveThreshold 函数.pdf》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、自适应阈值化的函数为:AdaptiveThreshold自适应阈值方法voidcvAdaptiveThreshold(constCvArr*src,CvArr*dst,doublemax_value,intadaptive_method=CV_ADAPTIVE_THRESH_MEAN_C,intthreshold_type=CV_THRESH_BINARY,intblock_size=3,doubleparam1=5);src输入图像.dst输出图像.max_value使用CV_THRESH_BINARY和CV_THRESH_BINARY_INV的最大值.adap
2、tive_method自适应阈值算法使用:CV_ADAPTIVE_THRESH_MEAN_C或CV_ADAPTIVE_THRESH_GAUSSIAN_C(见讨论).threshold_type取阈值类型:必须是下者之一CV_THRESH_BINARY,CV_THRESH_BINARY_INVblock_size用来计算阈值的象素邻域大小:3,5,7,...param1与方法有关的参数。对方法CV_ADAPTIVE_THRESH_MEAN_C和CV_ADAPTIVE_THRESH_GAUSSIAN_C,它是一个从均值或加权均值提取的常数(见讨论),尽管它可以是负
3、数。函数cvAdaptiveThreshold将灰度图像变换到二值图像,采用下面公式:threshold_type=CV_THRESH_BINARY:dst(x,y)=max_value,ifsrc(x,y)>T(x,y)0,otherwisethreshold_type=CV_THRESH_BINARY_INV:dst(x,y)=0,ifsrc(x,y)>T(x,y)max_value,otherwise其中TI是为每一个象素点单独计算的阈值对方法CV_ADAPTIVE_THRESH_MEAN_C,先求出块中的均值,再减掉param1。对方法CV_ADAPTIV
4、E_THRESH_GAUSSIAN_C,先求出块中的加权和(gaussian),再减掉param1。下面的例题对阈值化和自适应阈值化进行了比较:[cpp]viewplaincopy1.#include"StdAfx.h"2.#include3.#include4.#include5.IplImage*Igray=0;6.IplImage*It=0;7.IplImage*Iat;8.voidmain()9.{10.Igray=cvLoadImage("lena.png",CV_LOAD_IMAGE_GRAYSCALE
5、);11.It=cvCreateImage(cvSize(Igray->width,Igray->height),IPL_DEPTH_8U,1);12.Iat=cvCreateImage(cvSize(Igray->width,Igray->height),IPL_DEPTH_8U,1);13.cvThreshold(Igray,It,150,255,CV_THRESH_BINARY);14.cvAdaptiveThreshold(Igray,Iat,255,CV_ADAPTIVE_THRESH_MEAN_C,CV_THRESH_BINARY,3,5);15.cv
6、NamedWindow("orignal",1);16.cvNamedWindow("threshold",1);17.cvNamedWindow("adaptiveThresh",1);18.cvShowImage("orignal",Igray);19.cvShowImage("threshold",It);20.cvShowImage("adaptiveThresh",Iat);21.cvWaitKey(0);22.cvReleaseImage(&Igray);23.cvReleaseImage(&It);24.cvReleaseImage(&Iat);25
7、.cvDestroyWindow("orignal");26.cvDestroyWindow("threshold");27.cvDestroyWindow("adaptiveThresh");28.29.}