Ask Your Question
0

What is the Kernel Doing in a Blur Function?

asked 2013-11-07 17:21:06 -0600

dmcenan gravatar image

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-11-08 03:03:37 -0600

Guanta gravatar image

updated 2013-11-08 03:06:37 -0600

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)
edit flag offensive delete link more

Comments

Thanks for your reply Guanta!

dmcenan gravatar imagedmcenan ( 2013-11-13 16:58:04 -0600 )edit

Question Tools

Stats

Asked: 2013-11-07 17:21:06 -0600

Seen: 456 times

Last updated: Nov 08 '13