原文:Emgu-WPF学习使用-阈值化

环境:Win8 64位 Vs2015

Emgu 版本:emgucv-windesktop 3.2.0.2682

上图为常用阈值化处理效果。不同阈值设置可呈现不同处理效果。

       private void InitSourceFile(object sender, RoutedEventArgs e)
{
string sFile = "";
if (!String.IsNullOrEmpty(AppConstUtils.GDefaultFile) && File.Exists(AppConstUtils.GDefaultFile))
sFile = AppConstUtils.GDefaultFile;
else
sFile = GlobalVar.DATAS_PATH + "Samples/Test3.png";
BitmapImage oOriginBitSrc = new BitmapImage(new Uri(sFile)); this.ImgOrigin1Zm.Source = oOriginBitSrc;
System.Drawing.Image oImgOrigin = System.Drawing.Image.FromFile(sFile);
System.Drawing.Bitmap oBitmap = new System.Drawing.Bitmap(oImgOrigin);
Image<Bgr, byte> imgSrc = new Image<Bgr, byte>(oBitmap);
oBitmap.Dispose(); this.Func1(imgSrc);
this.Func2(imgSrc);
this.Func3(imgSrc);
this.Func4(imgSrc);
this.Func5(imgSrc);
} private void Func1(Image<Bgr, byte> imgSrc)
{
// 灰度化
Image<Gray, byte> imgGray = new Image<Gray, byte>(imgSrc.Size);
CvInvoke.CvtColor(imgSrc, imgGray, ColorConversion.Bgr2Gray);
AppUtils.ShowGrayImage(this.ImgFun1Result1Zm, imgGray);// 转换为BitmapSource呈现 // 二进制阈值化
Image<Gray, byte> imgThresholdBinary = new Image<Gray, byte>(imgGray.Size);
//90为阈值,可调整,255为最大值
CvInvoke.Threshold(imgGray, imgThresholdBinary, 90, 255, ThresholdType.Binary);
AppUtils.ShowGrayImage(this.ImgFun1Result2Zm, imgThresholdBinary); //反向二进制阈值化
Image<Gray, byte> imgThresholdBinaryInv = new Image<Gray, byte>(imgGray.Size);
CvInvoke.Threshold(imgGray, imgThresholdBinaryInv, 90, 255, ThresholdType.BinaryInv);
AppUtils.ShowGrayImage(this.ImgFun1Result3Zm, imgThresholdBinaryInv); //截断阈值化
Image<Gray, byte> imgThresholdTrunc = new Image<Gray, byte>(imgGray.Size);
CvInvoke.Threshold(imgGray, imgThresholdTrunc, 90, 255, ThresholdType.Trunc);
AppUtils.ShowGrayImage(this.ImgFun1Result4Zm, imgThresholdTrunc); //超阈值归零化
Image<Gray, byte> imgThresholdToZero = new Image<Gray, byte>(imgGray.Size);
CvInvoke.Threshold(imgGray, imgThresholdToZero, 90, 255, ThresholdType.ToZero);
AppUtils.ShowGrayImage(this.ImgFun1Result5Zm, imgThresholdToZero); //低于阈值归零化
Image<Gray, byte> imgThresholdToZeroInv = new Image<Gray, byte>(imgGray.Size);
CvInvoke.Threshold(imgGray, imgThresholdToZeroInv, 150, 255, ThresholdType.ToZeroInv);
AppUtils.ShowGrayImage(this.ImgFun1Result6Zm, imgThresholdToZeroInv); //Mask
Image<Gray, byte> imgThresholdMask = new Image<Gray, byte>(imgGray.Size);
CvInvoke.Threshold(imgGray, imgThresholdMask, 90, 255, ThresholdType.Mask);
AppUtils.ShowGrayImage(this.ImgFun1Result7Zm, imgThresholdMask); //Otsu
Image<Gray, byte> imgThresholdOtsu = new Image<Gray, byte>(imgGray.Size);
CvInvoke.Threshold(imgGray, imgThresholdOtsu, 150, 255, ThresholdType.Otsu);
AppUtils.ShowGrayImage(this.ImgFun1Result8Zm, imgThresholdOtsu);
} private void Func2(Image<Bgr, byte> imgSrc)
{
// 灰度化
Image<Gray, byte> imgGray = new Image<Gray, byte>(imgSrc.Size);
CvInvoke.CvtColor(imgSrc, imgGray, ColorConversion.Bgr2Gray); // 自适应阈值
Image<Gray, byte> imgAdapativeThresholdMeanC = imgGray.ThresholdAdaptive(new Gray(255),
AdaptiveThresholdType.MeanC, ThresholdType.Binary, 9, new Gray(5));
AppUtils.ShowGrayImage(this.ImgFun2Result1Zm, imgAdapativeThresholdMeanC);
} private void Func3(Image<Bgr, byte> imgSrc)
{
// 灰度化
Image<Gray, byte> imgGray = new Image<Gray, byte>(imgSrc.Size);
CvInvoke.CvtColor(imgSrc, imgGray, ColorConversion.Bgr2Gray); // 自适应阈值
Image<Gray, byte> imgAdapativeThresholdGaussianC = imgGray.ThresholdAdaptive(new Gray(255),
AdaptiveThresholdType.GaussianC, ThresholdType.Binary, 9, new Gray(5));
AppUtils.ShowGrayImage(this.ImgFun2Result2Zm, imgAdapativeThresholdGaussianC);
} private void Func4(Image<Bgr, byte> imgSrc)
{
// 灰度化
Image<Gray, byte> imgGray = new Image<Gray, byte>(imgSrc.Size);
CvInvoke.CvtColor(imgSrc, imgGray, ColorConversion.Bgr2Gray); // 自适应阈值
Image<Gray, byte> imgAdapativeThresholdMeanC = imgGray.ThresholdAdaptive(new Gray(255),
AdaptiveThresholdType.MeanC, ThresholdType.BinaryInv, 9, new Gray(5));
AppUtils.ShowGrayImage(this.ImgFun2Result3Zm, imgAdapativeThresholdMeanC);
} private void Func5(Image<Bgr, byte> imgSrc)
{
// 灰度化
Image<Gray, byte> imgGray = new Image<Gray, byte>(imgSrc.Size);
CvInvoke.CvtColor(imgSrc, imgGray, ColorConversion.Bgr2Gray); // 自适应阈值
Image<Gray, byte> imgAdapativeThresholdGaussianC = imgGray.ThresholdAdaptive(new Gray(255),
AdaptiveThresholdType.GaussianC, ThresholdType.BinaryInv, 9, new Gray(5));
AppUtils.ShowGrayImage(this.ImgFun2Result4Zm, imgAdapativeThresholdGaussianC);
}

另外:

 AppUtils.ShowGrayImage(Image oImg, Image<Bgr, byte> imgSrc); 在我的上一篇博客中有实现。
 点击打开链接  http://blog.csdn.net/u013224722/article/details/79613445

Emgu-WPF学习使用-阈值化的更多相关文章

  1. 灰度图像阈值化分割常见方法总结及VC实现

    转载地址:http://blog.csdn.net/likezhaobin/article/details/6915755 在图像处理领域,二值图像运算量小,并且能够体现图像的关键特征,因此被广泛使用 ...

  2. 【学习opencv第七篇】图像的阈值化

    图像阈值化的基本思想是,给定一个数组和一个阈值,然后根据数组中每个元素是低于还是高于阈值而进行一些处理. cvThreshold()函数如下: double cvThreshold( CvArr* s ...

  3. opencv学习之路(13)、图像阈值化threshold

    一.图像阈值化简介 二.固定阈值 三.自适应阈值 #include<opencv2/opencv.hpp> using namespace cv; void main(){ Mat src ...

  4. opencv2函数学习之threshold:实现图像阈值化

    在opencv2中,threshold函数可以进行阈值化操作. double threshold( const Mat& src, Mat& dst, double thresh,do ...

  5. WPF学习之路初识

    WPF学习之路初识   WPF 介绍 .NET Framework 4 .NET Framework 3.5 .NET Framework 3.0 Windows Presentation Found ...

  6. WPF 学习笔记-设置属性使窗口不可改变大小

    原文:WPF 学习笔记-设置属性使窗口不可改变大小 调整Windows下的ResizeMode属性: ResizeMode = NoResize Resize属性是控制Windows是否可以改变大小, ...

  7. 【数字图像处理】五.MFC图像点运算之灰度线性变化、灰度非线性变化、阈值化和均衡化处理具体解释

    本文主要讲述基于VC++6.0 MFC图像处理的应用知识,主要结合自己大三所学课程<数字图像处理>及课件进行解说.主要通过MFC单文档视图实现显示BMP图片点运算处理.包含图像灰度线性变换 ...

  8. WPF学习开发客户端软件-任务助手(下 2015年2月4日代码更新)

    时光如梭,距离第一次写的 WPF学习开发客户端软件-任务助手(已上传源码)  已有三个多月,期间我断断续续地对该项目做了优化.完善等等工作,现在重新向大家介绍一下,希望各位可以使用,本软件以实用性为主 ...

  9. OpenCV3编程入门笔记(4)腐蚀、膨胀、开闭运算、漫水填充、金字塔、阈值化、霍夫变换

    腐蚀erode.膨胀dilate 腐蚀和膨胀是针对图像中的白色部分(高亮部分)而言的,不是黑色的.除了输入输出图像外,还需传入模板算子element,opencv中有三种可以选择:矩形MORPH_RE ...

随机推荐

  1. sequence配置

    在实现分库分表的情况下,数据库自增主键已经无法保证在集群中是全局唯一的主键了,因此mycat提供了全局的sequence,并且提供了本地配置.数据库配置等多种实现方式. 本地文件方式 采用该方式,my ...

  2. windows phone 2048 源代码奉上

    小梦今天把2048的游戏源代码给大家分享一下,其实感觉这个重在算法,UI很简单,而且几乎没有用到什么windows phone的API.小梦遇到最主要的问题就是对触摸事件的处理,我刚开始想到的就是 M ...

  3. C#中使用split分割字符串的几种方法小结

    1.用字符串分隔: using System.Text.RegularExpressions;string str="aaajsbbbjsccc";string[] sArray= ...

  4. HDOJ 2043 password

    刚開始看到这个题目的时候,就直接理解成仅仅要是长度符合要求而且字符符合要求,就是一个安全的password了,并没有考虑到至少要3种字符的组合.然后就直接写程序了(先暂且觉得题目就是那个意思),在測试 ...

  5. [Grid Layout] Use the repeat function to efficiently write grid-template values

    We can use the repeat() function if we have repeating specifications for columns and rows. With the  ...

  6. signed 与 unsigned 有符号和无符号数

    unsigned int a = 0; unsigned int b = -1; // b 为 0xffffffff unsigned int c = a - 1; // c 为 0xffffffff

  7. produces在@requestMapping中的使用方式和作用

    produces可能不算一个注解,因为什么呢,它是注解@requestMapping注解里面的属性项, 它的作用是指定返回值类型,不但可以设置返回值类型还可以设定返回值的字符编码: 还有一个属性与其对 ...

  8. windows下 管理员身份启动java进程

    http://blog.csdn.net/zhuyijian135757/article/details/38234757

  9. SpringMVC大坑一枚:ContentNegotiatingViewResolver可能不利于SEO

    广大站长都有关注自己网站被搜索引擎收录的习惯,最近用百度.360等搜索引擎,查看了自己网站的一些情况,使用命令"site:fansunion.cn". 我发现了一些异常信息,不止一 ...

  10. 【u220】生日礼物

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 一对双胞胎兄妹同一天过生日,这一天,他们的朋友给他俩送来了礼物,每个人送的礼物都是2本书,一本给哥哥, ...