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/79613445Emgu-WPF学习使用-阈值化的更多相关文章
- 灰度图像阈值化分割常见方法总结及VC实现
转载地址:http://blog.csdn.net/likezhaobin/article/details/6915755 在图像处理领域,二值图像运算量小,并且能够体现图像的关键特征,因此被广泛使用 ...
- 【学习opencv第七篇】图像的阈值化
图像阈值化的基本思想是,给定一个数组和一个阈值,然后根据数组中每个元素是低于还是高于阈值而进行一些处理. cvThreshold()函数如下: double cvThreshold( CvArr* s ...
- opencv学习之路(13)、图像阈值化threshold
一.图像阈值化简介 二.固定阈值 三.自适应阈值 #include<opencv2/opencv.hpp> using namespace cv; void main(){ Mat src ...
- opencv2函数学习之threshold:实现图像阈值化
在opencv2中,threshold函数可以进行阈值化操作. double threshold( const Mat& src, Mat& dst, double thresh,do ...
- WPF学习之路初识
WPF学习之路初识 WPF 介绍 .NET Framework 4 .NET Framework 3.5 .NET Framework 3.0 Windows Presentation Found ...
- WPF 学习笔记-设置属性使窗口不可改变大小
原文:WPF 学习笔记-设置属性使窗口不可改变大小 调整Windows下的ResizeMode属性: ResizeMode = NoResize Resize属性是控制Windows是否可以改变大小, ...
- 【数字图像处理】五.MFC图像点运算之灰度线性变化、灰度非线性变化、阈值化和均衡化处理具体解释
本文主要讲述基于VC++6.0 MFC图像处理的应用知识,主要结合自己大三所学课程<数字图像处理>及课件进行解说.主要通过MFC单文档视图实现显示BMP图片点运算处理.包含图像灰度线性变换 ...
- WPF学习开发客户端软件-任务助手(下 2015年2月4日代码更新)
时光如梭,距离第一次写的 WPF学习开发客户端软件-任务助手(已上传源码) 已有三个多月,期间我断断续续地对该项目做了优化.完善等等工作,现在重新向大家介绍一下,希望各位可以使用,本软件以实用性为主 ...
- OpenCV3编程入门笔记(4)腐蚀、膨胀、开闭运算、漫水填充、金字塔、阈值化、霍夫变换
腐蚀erode.膨胀dilate 腐蚀和膨胀是针对图像中的白色部分(高亮部分)而言的,不是黑色的.除了输入输出图像外,还需传入模板算子element,opencv中有三种可以选择:矩形MORPH_RE ...
随机推荐
- php面试题8
php面试题8 一.总结 二.php面试题8 1.表单数据提交方式 POST 和 GET 的区别,URL 地址传递的数据最大长度是多少?$_GET 传参是请求 HTTP 协议通过 url 参数传递和接 ...
- 小梦词典WP8.1应用发布
这几天一直在做这款应用,今天终于发布了! 小梦词典简介: 小梦词典是一款永久免费无广告的网络词典. 支持英汉单词查询: 支持中,英,法,韩,德,俄,日七国语言翻译,多语言极致体验: 支持生词本记忆,查 ...
- 利用Powershell获取公司内部机器的资源信息,作为企业兴许资产管理的基本途径!
今天一个哥们问我是否用Powershell 实现.我好久没有写脚本,脚本的协作和调试还是费了一些时间,兴许调试了下.运作没有问题,大家能够參考以下的脚本来丰富您企业须要做的一些事情,脚本代码例如以下: ...
- [Angular] Adding keyboard events to our control value accessor component
One of the most important thing when building custom form component is adding accessbility support. ...
- [Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def
What about the situation in which we aren’t specifying the number of columns or rows to be repeated? ...
- [GraphQL] Add an Interface to a GraphQL Schema
As we start building out more complex GraphQL schemas, certain fields start to repeat across differe ...
- 基于 Android NDK 的学习之旅-----资源释放
做上一个项目的时候因为与C引擎交互频繁,有时候会突然莫名其妙的的整个应用程序直接挂掉.因为我是学Java 开始的,所以对主动释放内存没多大概念(GC直接帮忙回收),后查询原因才知道是因为JNI 有些对 ...
- 小强的HTML5移动开发之路(28)—— JavaScript回顾3
一.基本数据类型 number:数字类型 string:字符串 (注意s小写:string是基本类型) boolean:布尔类型 //前三个都有对应的包装类 null:空类型 undefined: ...
- 【网络】无法解析服务器的DNS地址?;能登陆QQ,无法打开网页
1. 无法解析服务器的DNS地址 手动设置 DNS(域名解析服务器) 8.8.8.8 114.114.114.114 清除浏览器缓存: 重启主机: 无法解析服务器的DNS地址?DNS解析错误怎么办? ...
- 几种tab切换尝试 原生js
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...