OpenCV-3.Thresholding
来源:互联网 发布:如何清空淘宝自动推荐 编辑:程序博客网 时间:2024/06/08 05:44
Thresholding
介绍
在图像处理中,Thresholding中文翻译过来叫二值化或者阈值化。二值化就是把图片传换成只有white和black这两种颜色。通过Thresholding,可以让图片中感兴趣的颜色变成主角--white,其余的颜色全部隐藏--black。另外,二值化后的图片也便于计算机进行分析,因为边缘轮廓十分清晰,所以计算机可以轻松找到边界线。然而,在这方面,Thresholding并不是顶好的算法,有些时候遇到某些特殊图片效果也不好。
代码演示
#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/highgui/highgui.hpp"#include "cv.h"int main(){//读取图片IplImage* img = cvLoadImage("6.jpg"); //创建3个图片来保存原图中的各个通道IplImage* redchannel = cvCreateImage(cvGetSize(img),8,1);IplImage* greenchannel = cvCreateImage(cvGetSize(img),8,1);IplImage* bluechannel = cvCreateImage(cvGetSize(img),8,1);//获得各个通道信息cvSplit(img,bluechannel,greenchannel,redchannel,NULL);//观察单通道图像cvNamedWindow("redchannel");cvNamedWindow("bluechannel");cvNamedWindow("greenchannel");cvShowImage("redchannel",redchannel);cvShowImage("bluechannel",bluechannel);cvShowImage("greenchannel",greenchannel);/*由于我们是想分离出红色,所以我们应当关注red channel,请观察文章中图一,这是三个通道各自的图像,最左是red channel,所以红色明亮一些,其余颜色暗淡些,但是注意,白色也是明亮的,因为white = r + g + b,中间图是green channel,绿色亮一些,红色又会暗淡些,但是白色依然也很亮,最后是blue channel,由于原图中蓝色不怎么明显,所以,blue channel中就白色明亮些。我们需要只关注red channel,所以,我们需要从red channel中把包括白色的公共部分去掉即,需要如此:red = red - (blue + green)下面两句便是实现这个计算式的代码*/cvAdd(bluechannel,greenchannel,greenchannel);//green = blue + greencvSub(redchannel,greenchannel,redchannel); //red = red - green.//Threshold操作:参数1:src,参数2:dst.//20是阈值,大于20的直接255,所以之前的red就变white了。该函数具体用法可以googlecvThreshold(redchannel,redchannel,20,255,CV_THRESH_BINARY);//showcvNamedWindow("original");cvNamedWindow("red");cvShowImage("original",img);cvShowImage("red",redchannel);cvWaitKey(0);return 0;}
图一:
图二:
1 0
- OpenCV-3.Thresholding
- Thresholding
- Thresholding
- Otsu thresholding
- Adaptive Thresholding
- soft thresholding
- Otsu Thresholding
- Otsu Thresholding
- soft thresholding and hard thresholding
- soft thresholding and hard thresholding
- 雙重閥值(Dual thresholding)
- 單一閥值(Single thresholding)
- 5 types of thresholding
- 例5-4 Compare thresholding with adaptive thresholding
- IST:Iterative Shrinkage/Thresholding和Iterative Soft Thresholding
- soft thresholding 软阈值算法
- soft thresholding 软阈值算法
- algo_FISTA(fast shrinkage-thresholding algorithm)
- 从Spark架构中透视job
- HTML中<!DOCTYPE>标签的作用
- qt数据库及密钥操作
- Android 自定义View UC下拉刷新效果(二)
- maven项目自动构建时的pom.xml文件中的build
- OpenCV-3.Thresholding
- Android 正则表达式
- mysql处理高并发,防止库存超卖
- Is There A Second Way Left? (UVA 10462)【kruskal 求次小生成树存在】
- 用Javascript实现对HTML表格简单的增删查改
- Linux ALSA声卡驱动之五:移动设备中的ALSA(ASoC)
- textFieldShouldReturn: 方法无效化!
- 使用XX-net实现代理访问国外网站
- 从心开始学Android:ListView