原文: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. js javascript正则

    var re = new RegExp("^[0-9]$"); 或者 var re2 = /^\d$/;//这个好像兼容性更好,比如你在上面的语句里面写\d,就总是返回false, ...

  2. ios开发事件处理之:五:事件的响应

  3. 给自己加油,一定要学会MFC!(刚刚发现一篇文章,兼听则明: MFC,一开始就错了)

    我自己对于没有学会MFC始终耿耿于怀,都什么时代了啊,但是我仍然坚持会去学MFC,因为MFC虽然落后与复杂,但是在Windows平台上仍然是无所不能的(其实Windows平台仍然是唯一可以赚钱的平台, ...

  4. 学习web开发遇到几个细节问题

    1.在jsp中使用jsp表达式在input标签中时,避免直接和结束"/"相连 2.提取input select 标签内的内容,使用...value提取其值 3.form中含有一个o ...

  5. push的时候隐藏底部的tabbar

    push的时候隐藏底部的tabbar #import "mainNavigationControllers.h" @interface mainNavigationControll ...

  6. [GeekBand] STL vector 查找拷贝操作效率分析

    本文参考文献::GeekBand课堂内容,授课老师:张文杰 :C++ Primer 11 中文版(第五版) :网络资料: 叶卡同学的部落格  http://www.leavesite.com/ htt ...

  7. freemarker中间split字符串切割

    freemarker中间split字符串切割 1.简易说明 split切割:用来依据另外一个字符串的出现将原字符串切割成字符串序列 2.举例说明 <#--freemarker中的split字符串 ...

  8. iOS 使用贝塞尔曲线绘制路径

    使用贝塞尔曲线绘制路径 大多数时候,我们在开发中使用的控件的边框是矩形,或者做一点圆角,是使得矩形的角看起来更加的圆滑. 但是如果我们想要一个不规则的图形怎么办?有人说,叫UI妹子做,不仅省事,还可以 ...

  9. 【17.00%】【codeforces 621D】Rat Kwesh and Cheese

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  10. Objective-C 数据类型 (一)

    数据类型分为三类:基本数据类型,对象类型,id类型. 基本数据类型:int ,float double char 对象类型:类,指针对象,协议 id类型:可以表示对象类型(在表示对象类型的时候 不需要 ...