C#:图像二值化

2023-08-29  本文已影响0人  大龙10

一、基本阈值化

public static double Threshold(InputArray src, OutputArray dst, double thresh, double maxval, ThresholdTypes type);

二、自适应阈值化

三、程序

二值化
       private void uiButton6_Click(object sender, EventArgs e)
        {
            Mat result = src_img.Clone();
            Mat imgLab = new Mat();
            Cv2.CvtColor(src_img, imgLab, ColorConversionCodes.BGR2Lab);
            Mat[] labArray = Cv2.Split(imgLab); //L, a, b
            Mat blur = new Mat();
            Cv2. GaussianBlur(labArray[0], blur, new OpenCvSharp.Size(3, 3), 0); //b通道
            Mat m6 = new Mat();

            string s_yuzhi = uiTextBox2.Text;
            //不用大律法二值化;大律法二值的不好

            Cv2.Threshold(blur, m6, s_yuzhi.ToInt(), 255, ThresholdTypes.BinaryInv);

             m6.CopyTo(dst);
             pictureBox1.Image = m6.ToBitmap();

        }

四、资料

知乎:
https://zhuanlan.zhihu.com/p/473304766
上一篇下一篇

猜你喜欢

热点阅读