如何在 EMGU CV 中为 filter2d 定义内核

问题描述 投票:0回答:1

我想通过使用锐化内核执行 CvInvoke.Filter2d 来锐化图像: {[-1,-1,-1],[-1, 9,-1],[-1,-1,-1]}

如何在 C# 下的 EMGU 中定义这个内核?

我使用的是 EMGU 版本 4.3.0.3890

这是我的代码:

        // Load image
        Image<Bgr, Byte> img = null;
        img = new Image<Bgr, byte>(@"D:\Sample.png");
        
        // Convert the image to grayscale
        Image<Gray, float> gray = img.Convert<Gray, float>()
        .ThresholdBinary(new Gray(150), new Gray(255));

        // Add use of Filter2D here
emgucv
1个回答
4
投票
        // Load image
        Image<Bgr, byte> img = new Image<Bgr, byte>(@"path/img.jpg");

        // Convert the image to grayscale
        Image<Gray, byte> gray = img.Convert<Gray, byte>().ThresholdBinary(new Gray(150), new Gray(255));

        // Add use of Filter2D here
        CvInvoke.Imshow("GrayImage", gray);

        float[,] matrix = new float[3, 3] {
                      { 1, 1, 1 },
                      {  1, -9, 1},
                      { 1, 1, 1 }
                    };
        ConvolutionKernelF matrixKernel = new ConvolutionKernelF(matrix);

        var dst = new Mat(gray.Size, DepthType.Cv8U, 1);
        CvInvoke.Filter2D(gray, dst, matrixKernel, new Point(0, 0));

        CvInvoke.Imshow("FiltredImage", dst);

        CvInvoke.WaitKey(0);

PS:

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.