`
yingyingol
  • 浏览: 744810 次
文章分类
社区版块
存档分类
最新评论

OpenCV学习笔记-阈值化

 
阅读更多

需要的几个函数:

Threshold

對數組元素進行固定閾值操作

void cvThreshold( const CvArr* src, CvArr* dst, double threshold,
                  double max_value, int threshold_type );
src
原始數組 (單通道 , 8-bit of 32-bit 浮點數).
dst
輸出數組,必須與 src 的類型一致,或者為 8-bit.
threshold
閾值
max_value
使用 CV_THRESH_BINARY 和 CV_THRESH_BINARY_INV 的最大值.
threshold_type
閾值類型 (見討論)

函數 cvThreshold 對單通道數組應用固定閾值操作。該函數的典型應用是對灰度圖像進行閾值操作得到二值圖像。(cvCmpS 也可以達到此目的) 或者是去掉噪聲,例如過濾很小或很大象素值的圖像點。本函數支持的對圖像取閾值的方法由 threshold_type 確定:

threshold_type=CV_THRESH_BINARY:
dst(x,y) = max_value, if src(x,y)>threshold
           0, otherwise

threshold_type=CV_THRESH_BINARY_INV:
dst(x,y) = 0, if src(x,y)>threshold
           max_value, otherwise

threshold_type=CV_THRESH_TRUNC:
dst(x,y) = threshold, if src(x,y)>threshold
           src(x,y), otherwise

threshold_type=CV_THRESH_TOZERO:
dst(x,y) = src(x,y), if (x,y)>threshold
           0, otherwise

threshold_type=CV_THRESH_TOZERO_INV:
dst(x,y) = 0, if src(x,y)>threshold
           src(x,y), otherwise

下面是圖形化的閾值描述:






具体实现例题为:


运算结果为:


另外一种实现方式为,该种实现方式目标图像与原图像一致,再次采用cvConvertScale实现,

还需要用到cvAcc函数,为



具体实现代码:


该运算结果有问题,显示结果为白色,还没找到原因。

如图,

参考文献:

1.学习OpenCV,于仕祺,刘瑞祯,清华大学出版社,pp.155-159

2.http://www.opencv.org.cn/index.php/Cxcore%E6%95%B0%E7%BB%84%E6%93%8D%E4%BD%9C

3.http://www.opencv.org.cn/index.php/Cv%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86#Threshold

4.http://blog.csdn.net/cartoonface/article/details/5998827

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics