Emgucv图像处理二

Emgucv图像处理

阈值Threshold

 private void button7_Click(object sender, EventArgs e)
        {
            //阈值
            Mat scr = new Mat("001.jpg", Emgu.CV.CvEnum.ImreadModes.Grayscale);
            Mat dst = new Mat();
            CvInvoke.Threshold(scr, dst, 60, 255, ThresholdType.Binary);
            Mat dst1 = new Mat();
            CvInvoke.Threshold(scr, dst1, 60, 255, ThresholdType.BinaryInv);
            Mat dst2 = new Mat();
            CvInvoke.Threshold(scr, dst2, 60, 255, ThresholdType.Otsu);
            Mat dst3 = new Mat();
            CvInvoke.Threshold(scr, dst3, 10, 255, ThresholdType.ToZero);
            Mat dst4 = new Mat();
            CvInvoke.Threshold(scr, dst4, 10, 255, ThresholdType.ToZeroInv);
            Mat dst5 = new Mat();
            CvInvoke.Threshold(scr, dst5, 60, 255, ThresholdType.Trunc);

            imageBox1.Image = scr;
            imageBox2.Image = dst;
            imageBox3.Image = dst1;
            imageBox3.Image = dst2;
            imageBox3.Image = dst3;
            imageBox3.Image = dst4;
            imageBox3.Image = dst5;
        }

局部阈值AdaptiveThreshold

private void button8_Click(object sender, EventArgs e)
        {
            //局部阈值
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.Grayscale);
            Mat dst = new Mat();
            CvInvoke.AdaptiveThreshold(scr, dst, 255, AdaptiveThresholdType.GaussianC,Emgu.CV.CvEnum.ThresholdType.BinaryInv, 3, -10);
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

中值滤波MedianBlur

private void button9_Click(object sender, EventArgs e)
        {
            //中值滤波
            Mat scr = new Mat("003.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat();
            CvInvoke.MedianBlur(scr, dst, 3);
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

均值滤波Blur

 private void button10_Click(object sender, EventArgs e)
        {
            //均值滤波
            Mat scr = new Mat("003.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat();
            CvInvoke.Blur(scr, dst,new Size(3,3),new Point(-1,1));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

 高斯滤波GaussianBlur

 private void button11_Click(object sender, EventArgs e)
        {
            //高斯滤波
            Mat scr = new Mat("003.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat();
            CvInvoke.GaussianBlur(scr, dst, new Size(3, 3),3);
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

双边滤波BilateralFilter

 private void button12_Click(object sender, EventArgs e)
        {
            //双边滤波
            Mat scr = new Mat("001.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat();
            CvInvoke.BilateralFilter(scr, dst, 10,100,15);
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

方框滤波BoxFilter

private void button13_Click(object sender, EventArgs e)
        {
            //方框滤波
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat();
            CvInvoke.BoxFilter(scr, dst,DepthType.Cv8U,new Size(5,5),new Point(-1,-1));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

自定义滤波Filter2D

        private void button14_Click(object sender, EventArgs e)
        {
            //自定义滤波
            int[,,] data=new int[,,]{{{-1},{0},{1}},{{-2},{0},{2}},{{-1},{0},{1}}};
            Image kernel=new Image (data);
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            CvInvoke.Filter2D(scr, dst,kernel, new Point(-1,-1));
           // CvInvoke.Normalize(dst, dst, 0, 255, NormType.MinMax);
            imageBox1.Image = scr;
            imageBox2.Image = dst;
            
        }

腐蚀Erode

 private void button15_Click(object sender, EventArgs e)
        {
            //腐蚀
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.Erode(scr, dst, struct_element, new Point(-1, -1), 1, BorderType.Default, new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

膨胀Dilate

private void button16_Click(object sender, EventArgs e)
        {
            //膨胀
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.Dilate(scr, dst, struct_element, new Point(-1, -1), 1, BorderType.Default, new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

闭运算,先膨胀后腐蚀MorphologyEx--MorphOp.Close

private void button17_Click(object sender, EventArgs e)
        {
            //闭运算,先膨胀后腐蚀
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(scr, dst,MorphOp.Close, struct_element, new Point(-1, -1), 3, BorderType.Default,
                new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

开运算,先膨胀后腐蚀MorphologyEx--MorphOp.Open

 private void button18_Click(object sender, EventArgs e)
        {
            //开运算,先膨胀后腐蚀
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(scr, dst, MorphOp.Open, struct_element, new Point(-1, -1), 1, BorderType.Default,
                new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

形态学梯度MorphologyEx--MorphOp.Gradient

 private void button19_Click(object sender, EventArgs e)
        {
            //形态学梯度
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(scr, dst, MorphOp.Gradient, struct_element, new Point(-1, -1),1, BorderType.Default,
                new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

高帽MorphologyEx--MorphOp.Tophat

private void button20_Click(object sender, EventArgs e)
        {
            //高帽
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(scr, dst, MorphOp.Tophat, struct_element, new Point(-1, -1), 1, BorderType.Default,
                new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

低帽MorphologyEx--MorphOp.Blackhat

   private void button21_Click(object sender, EventArgs e)
        {
            //低帽
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(scr, dst, MorphOp.Blackhat, struct_element, new Point(-1, -1), 1, BorderType.Default,
                new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }


你可能感兴趣的:(c#)