• 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);
            }

    效果如下

  • 相关阅读:
    Glide优化
    Java多线程知识点
    Android知识点
    Gradle的一些技巧和遇到的问题
    Python用Django写restful api接口
    Python写爬虫爬妹子
    用最简单的例子说明设计模式(三)之责任链、建造者、适配器、代理模式、享元模式
    【Python】扫描指定文件夹下特定后缀的文件
    【Python】生成多级树结构的xml文件
    【转】【Linux】安装pyinstaller
  • 原文地址:https://www.cnblogs.com/noigel/p/11007788.html
Copyright © 2020-2023  润新知