使用 emgu 锐化图像

信息处理 图像处理 opencv C#
2022-02-06 22:00:38

我有 c# 桌面应用程序,并且正在使用 emgu 框架作为 OpenCV 的包装器。

我正在尝试锐化图像,因为输入图像不是很好。

我厌倦了通过搜索从原始图像中找到的一种技术:

我拿了一份并模糊了它。然后我再复制一份原件并将其反转。
然后我将 2 个新图像合并在一起。
然后我最终反转了合并后的图像。

我已经完成了所有这些,但图像看起来几乎相同。

这是正确的方法吗?

如果需要,我可以发布我的代码——不过我使用 Aforge 来快速测试这种方法。

更新:为了回答我自己的问题,我使用了这个:

            Image<Bgr, byte> image = new Image<Bgr, byte>(@"D:\20140320022038047.jpg");
            Image<Bgr, byte> image2 = new Image<Bgr, byte>(@"D:\20140320022038047.jpg");
            Emgu.CV.CvInvoke.cvSmooth(image, image2, SMOOTH_TYPE.CV_GAUSSIAN, 5, 5, 9, 9);
            Emgu.CV.CvInvoke.cvAddWeighted(image, 1.5, image2, -0.5, 0, image);
1个回答

我知道这个答案很晚,但我认为这个问题值得回答

您使用的算法如下:

  1. 使用具有给定 Mask Size 和 Sigma 的高斯滤波器模糊原始图像

  2. 从原始图像中减去模糊图像(结果称为Mask)以消除背景并获得边缘区域

  3. 通过将掩码(仅边缘)乘以 K 将掩码中的加权部分添加到原始图像以增强边缘区域

K:用户输入(如果 K = 1 Unsharp,如果 K > 1 Highboost)

蒙版(x,y) = 原点(x,y) – 模糊(x,y)

结果(x,y) = 原点(x,y) + K × Mask(x,y)

这是代码:

public static Image<Gray, byte> Sharpen(Image<Gray, byte> image, int w, int h, double sigma1, double sigma2, int k)
    {
        w = (w % 2 == 0) ? w - 1 : w;
        h = (h % 2 == 0) ? h - 1 : h;
        //apply gaussian smoothing using w, h and sigma 
        var gaussianSmooth = image.SmoothGaussian(w, h, sigma1, sigma2);
        //obtain the mask by subtracting the gaussian smoothed image from the original one 
        var mask = image - gaussianSmooth;
        //add a weighted value k to the obtained mask 
        mask *= k;
        //sum with the original image 
        image += mask;
        return image;
    }

我认为你的问题是你没有从原始图像中减去平滑图像,无论如何我希望这有帮助