How to detect the kernel size for Gaussian Blurring?

Viewed 442

I am preprocessing an image to improve the results of tesseract. Therefore, I want to blur an image using OpenCV, so that OpenCV is able to detect shapes and therefore draw bounding boxes. However I am having problems setting the correct kernel size.

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.

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. Also, it says that the kernel size must be positive and odd, but that's it.

Why is (5,5) chosen here and not, for example, (3,3) or (7,7)? And is it advisable to always use the same numbers or do you also take (1,3) or (5,3)? How do I know which is the 'best' kernel size, or how do I at least get a good initial value?

I would be very happy about your answers, many thanks in advance!

1 Answers

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. Increasing the standard deviation will increase the effective kernel size.

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. By selecting a kernel size parameters six times the standard deviation the border parameters will be 1% or lower than the center parameter.

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.

Unfortunately, the choice of the standard variation and kernel size of your gaussian filter is extremely application dependent. 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

Related