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

    效果如下

  • 相关阅读:
    推荐一款作图工具
    web应用中幂等性的学习
    读书笔记:重构原则
    /usr/bin/ld: cannot find -lc错误原因及解决方法
    ar命令学习
    Linux下C语言编程中库的使用
    idea实战技巧
    intelj idea中除了Find Usage外的另一种查找级联调用的方法
    jenkins构建,拉取不到最新版本代码,报clock of the subversion server appears to be out of sync
    服务器出现大量close_wait,我们来说说到底是怎么回事?(以tomcat为例)
  • 原文地址:https://www.cnblogs.com/noigel/p/11007788.html
Copyright © 2011-2022 走看看