简体   繁体   English

如何检测高斯模糊的 kernel 尺寸?

[英]How to detect the kernel size for Gaussian Blurring?

I am preprocessing an image to improve the results of tesseract.我正在预处理图像以改善 tesseract 的结果。 Therefore, I want to blur an image using OpenCV, so that OpenCV is able to detect shapes and therefore draw bounding boxes.因此,我想使用 OpenCV 模糊图像,以便 OpenCV 能够检测形状并因此绘制边界框。 However I am having problems setting the correct kernel size.但是我在设置正确的 kernel 大小时遇到问题。

Below is an example of a document I currently work with.下面是我目前使用的文档示例。 Please ignore the arrows and hand written words, since my documents are all written with a computer.请忽略箭头和手写文字,因为我的文件都是用电脑写的。 https://www.fernstudi.net/magazin/14117

I have now read a few articles on the subject and also know by now that the kernel size specifies how many and which pixels in the environment of the target pixel should be considered.我现在已经阅读了有关该主题的几篇文章,并且现在还知道 kernel 大小指定了应考虑目标像素环境中的多少像素和哪些像素。

However, I ask myself how to know how big this parameter should be.但是,我问自己如何知道这个参数应该有多大。 For example, the OpenCV documentation simply chooses the value (5,5) - which seems pretty arbitrary to me.例如, OpenCV 文档只是选择了值 (5,5) - 这对我来说似乎很随意。 Also, it says that the kernel size must be positive and odd, but that's it.此外,它说 kernel 尺寸必须是正数和奇数,但仅此而已。

Why is (5,5) chosen here and not, for example, (3,3) or (7,7)?为什么在这里选择 (5,5) 而不是 (3,3) 或 (7,7)? And is it advisable to always use the same numbers or do you also take (1,3) or (5,3)?是否建议始终使用相同的数字,或者您也使用 (1,3) 或 (5,3)? How do I know which is the 'best' kernel size, or how do I at least get a good initial value?我怎么知道哪个是“最好的”kernel 尺寸,或者我如何至少获得一个好的初始值?

I would be very happy about your answers, many thanks in advance!我会很高兴你的回答,非常感谢提前!

When using the Gaussian Blur there are some things to play with.使用高斯模糊时,有一些东西可以玩。 The standard deviation/variance and the radius/kernel size.标准偏差/方差和半径/内核大小。

The standard deviation for a two-dimensional kernel is the radius in pixels containing 68% of the integrated magnitude of the coefficients.二维 kernel 的标准偏差是包含 68% 的系数积分幅度的像素半径。 Increasing the standard deviation will increase the effective kernel size.增加标准偏差将增加有效的 kernel 大小。

The size of the kernel should normally be selected large enough so that the kernel coefficients of the border rows and columns contribute very little to the sum of coefficients. kernel 的大小通常应选择得足够大,以使边界行和列的 kernel 系数对系数总和的贡献很小。 By selecting a kernel size parameters six times the standard deviation the border parameters will be 1% or lower than the center parameter.通过选择 kernel 尺寸参数的六倍标准偏差,边框参数将比中心参数低 1% 或更低。

In opencv, the function cv2.GaussianBlur(src, ksize, sigmaX, sigmaY, borderType) allows you to play not only with the kernel size but with the standard deviation of each axis.在 opencv 中,function cv2.GaussianBlur(src, ksize, sigmaX, sigmaY, borderType)不仅允许您使用 Z50484C19F1AFDAF3841ZA0D 的每个轴的标准偏差,还可以使用 8 个标准差。

Unfortunately, the choice of the standard variation and kernel size of your gaussian filter is extremely application dependent.不幸的是,您的高斯滤波器的标准变化和 kernel 尺寸的选择非常依赖于应用程序。 So, there is no absolute truth.所以,没有绝对的真理。 However, typically, you want to choose a gaussian filter such that you are considerable amount of high frequency components in your image.但是,通常,您希望选择一个高斯滤波器,这样您的图像中就有大量的高频分量。

You could provide an example image with which you are working with.您可以提供一个您正在使用的示例图像。

Hope it works.希望它有效。

Info from: Link1 Link2信息来自: Link1 Link2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM