# What is the Kernel Doing in a Blur Function?

Hi Folks, If I have the following input pixels and I apply the blur funtion below, what value will the middle pixel change to? In the case of a 3x3 kernel, does OpenCV take all 9 pixels and then use the average for the "new" middle pixel changing it from 50 to 94? Or does it take the average of all pixels in the 3x3 kernel except the middle pixel, which would mean 50 changes to 100?

Also, does it make sense to use a kernel size of (1,1)? This does work and OpenCv will process an image and change the pixels but I am not sure what pixels it considers for a kernel size of (1,1). In all cases the anchor is in the center of the kernel.

Thanks!

100 100 100

100 50 100

100 100 100

blur(image, result, Size(3,3), Point(-1,-1));

edit retag close merge delete

Sort by ยป oldest newest most voted

The middle pixel will be taken into account, i.e. in your example it will change to 94.

Small python-example to illustrate it:

>>> a = np.array([100,100,100,100,50,100,100,100,100]).reshape(3,-1)
>>> cv2.blur(a, (3,3))
array([[78, 89, 78],
[89, 94, 89],
[78, 89, 78]], dtype=int32)


(Note, the border pixels change here as well, since the border-pixels are interpolated).

No, a kernel size of (1,1) doesn't make sense and will have no effect (then each pixel will just be divided by 1).

>>> cv2.blur(a, (1,1))
array([[100, 100, 100],
[100,  50, 100],
[100, 100, 100]], dtype=int32)

more