zoukankan      html  css  js  c++  java
  • Emgu 学习(7)threshold ,图像过滤

    Threshold

    代码如下

            static void Main(String[] args)
            {
                Mat img = CvInvoke.Imread(@"C:UsersdellPicturesfacesGray.png", ImreadModes.Grayscale);
                Mat dst = new Mat();
                double thresholdValue = 122;
                double max = 255;
                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(0);
            }

    例子

        class Program
        {
            static void Main(String[] args)
            {
                Mat img = CvInvoke.Imread(@"C:UsersdellPicturesfaces.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(0);
            }
            static Mat sum_rgb(Mat src,Mat dst)
            {
                int ch = src.NumberOfChannels;
                VectorOfMat vMat = new VectorOfMat(ch);
                CvInvoke.Split(src, vMat);
                Mat b = vMat[0];
                Mat g = vMat[1];
                Mat r=  vMat[2];
                Mat s = new Mat();
                CvInvoke.AddWeighted(r, 1.0 / 3, g, 1.0 / 3, 0.0,s);
                CvInvoke.AddWeighted(s, 1.0, b, 1.0 / 3, 0.0, s);
                CvInvoke.Threshold(s, dst, 100, 100, ThresholdType.Trunc);
                return s;
            }
        }

    自适应Threshold

    代码

            static void Main(String[] args)
            {
                Mat img = CvInvoke.Imread(@"C:UsersdellPicturesfaces.png",0);
                Mat Gaussian = new Mat();
                Mat Mean = new Mat();
                CvInvoke.AdaptiveThreshold(img, Gaussian, 255, AdaptiveThresholdType.GaussianC, ThresholdType.Binary, 11, 5);
                CvInvoke.AdaptiveThreshold(img, Mean, 255, AdaptiveThresholdType.MeanC, ThresholdType.Binary, 11, 5);
                CvInvoke.Imshow("src", img);
                CvInvoke.Imshow("Gaussian", Gaussian);
                CvInvoke.Imshow("Mean", Mean);
                CvInvoke.WaitKey(0);
            }

    代码

            static void Main(String[] args)
            {
                Mat img = CvInvoke.Imread(@"C:UsersdellPicturesfaces.png");
    
                Mat dst = new Mat();
                CvInvoke.BoxFilter(img, dst, DepthType.Default, new Size(3, 3), new Point(-1, -1));
                CvInvoke.Imshow("src", img);
                CvInvoke.Imshow("boxFilter", dst);
                CvInvoke.Blur(img, dst, new Size(5, 5), new Point(-1, -1));
                CvInvoke.Imshow("blur", dst);
                CvInvoke.GaussianBlur(img, dst, new Size(5, 5), 1);
                CvInvoke.Imshow("Gaussian", dst);
                CvInvoke.MedianBlur(img, dst, 3);
                CvInvoke.Imshow("median", dst);
                CvInvoke.BilateralFilter(img, dst, 5, 30.0, 2.0);
                CvInvoke.Imshow("Bilateral", dst);
                CvInvoke.WaitKey(0);
            }

    效果如下

  • 相关阅读:
    Maven之——仓库(下)
    《Java虚拟机原理图解》3、JVM执行时数据区
    uva 784 Maze Exploration(简单dfs)
    debian下安装mysql
    关于Go语言,自己定义结构体标签的一个妙用.
    [BI项目记]-BUG处理
    怎样加入cocostudio生成的UI到项目
    python 将有序list打乱
    Android之旅十四 android中的xml文件解析
    h5 localStorage存储大小(转)
  • 原文地址:https://www.cnblogs.com/noigel/p/11007788.html
Copyright © 2011-2022 走看看