Emgu 学习(7)threshold ,图像过滤
2024-09-06 01:03:40
Threshold
代码如下
static void Main(String[] args)
{
Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\facesGray.png", ImreadModes.Grayscale);
Mat dst = new Mat();
double thresholdValue = ;
double max = ;
CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.Binary);
CvInvoke.Imshow("src", img);
CvInvoke.Imshow("Binary", dst);
CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.BinaryInv);
CvInvoke.Imshow("BinaryInv", dst);
CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.Otsu);
CvInvoke.Imshow("Otsu", dst); CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.ToZero);
CvInvoke.Imshow("ToZero", dst); CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.ToZeroInv);
CvInvoke.Imshow("ToZeroInv", dst); CvInvoke.Threshold(img, dst, thresholdValue, max, ThresholdType.Trunc);
CvInvoke.Imshow("Trunc", dst);
CvInvoke.WaitKey();
}
例子
class Program
{
static void Main(String[] args)
{
Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\faces.png");
Mat dst = new Mat();
Mat weighted = new Mat();
weighted = sum_rgb(img, dst).Clone();
CvInvoke.Imshow("src", img);
CvInvoke.Imshow("weighted", weighted);
CvInvoke.Imshow("dst", dst);
CvInvoke.WaitKey();
}
static Mat sum_rgb(Mat src,Mat dst)
{
int ch = src.NumberOfChannels;
VectorOfMat vMat = new VectorOfMat(ch);
CvInvoke.Split(src, vMat);
Mat b = vMat[];
Mat g = vMat[];
Mat r= vMat[];
Mat s = new Mat();
CvInvoke.AddWeighted(r, 1.0 / , g, 1.0 / , 0.0,s);
CvInvoke.AddWeighted(s, 1.0, b, 1.0 / , 0.0, s);
CvInvoke.Threshold(s, dst, , , ThresholdType.Trunc);
return s;
}
}
自适应Threshold
代码
static void Main(String[] args)
{
Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\faces.png",);
Mat Gaussian = new Mat();
Mat Mean = new Mat();
CvInvoke.AdaptiveThreshold(img, Gaussian, , AdaptiveThresholdType.GaussianC, ThresholdType.Binary, , );
CvInvoke.AdaptiveThreshold(img, Mean, , AdaptiveThresholdType.MeanC, ThresholdType.Binary, , );
CvInvoke.Imshow("src", img);
CvInvoke.Imshow("Gaussian", Gaussian);
CvInvoke.Imshow("Mean", Mean);
CvInvoke.WaitKey();
}
代码
static void Main(String[] args)
{
Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\faces.png"); Mat dst = new Mat();
CvInvoke.BoxFilter(img, dst, DepthType.Default, new Size(, ), new Point(-, -));
CvInvoke.Imshow("src", img);
CvInvoke.Imshow("boxFilter", dst);
CvInvoke.Blur(img, dst, new Size(, ), new Point(-, -));
CvInvoke.Imshow("blur", dst);
CvInvoke.GaussianBlur(img, dst, new Size(, ), );
CvInvoke.Imshow("Gaussian", dst);
CvInvoke.MedianBlur(img, dst, );
CvInvoke.Imshow("median", dst);
CvInvoke.BilateralFilter(img, dst, , 30.0, 2.0);
CvInvoke.Imshow("Bilateral", dst);
CvInvoke.WaitKey();
}
效果如下
最新文章
- Ajax方式上传文件
- .NET平台开源项目速览(3)小巧轻量级NoSQL文件数据库LiteDB
- php时间戳之间相互转换
- Sublime 3114 + 转换GBK方法
- 深入研究Clang(三) libclang
- KindEditor图片上传到七牛云
- POJ 1135 Domino Effect(Dijkstra)
- Delphi实现无标题有边框的窗体
- 关于C函数的参数个数的问题
- Java-老夫对泛型的理解。。
- Servlet3.0新特性使用详解
- (工具类)double类型数据运算
- 【codeforces 698C】LRU
- NodeJs操作MongoDB之分页功能与常见问题
- 根据不同访问设备跳转到PC页面或手机页面
- Latex常用软件
- Java设计模式学习记录-外观模式
- java的数组和arraylist
- Trove系列(八)——Trove的配置管理相关的功能介绍
- IOS微信后台运行时候倒计时暂停问题