Averaging filter

You can use both cv2.blur() and cv2.boxFilter() to perform an averaging by convolving the image with a kernel, which can be unnormalized in the case of cv2.boxFilter(). They simply take the average of all the pixels under the kernel area and replace the central element with this average. You can control the kernel size and the anchor kernel (by default (-1,-1), meaning that the anchor is located at the kernel center). When the normalize parameter (by default True) of cv2.boxFilter() is equal to True, both functions perform the same operation. In this way, both functions smooth an image using the kernel, as shown in the following expression:

In the case of the cv2.boxFilter() function:

 

In the case of the cv2.blur() function:

In other words, cv2.blur() always uses a normalized box filter, as shown in the following code: 

smooth_image_b = cv2.blur(image, (10, 10))
smooth_image_bfi = cv2.boxFilter(image, -1, (10, 10), normalize=True)

In the preceding code, the two lines of code are equivalent.