官术网_书友最值得收藏!

Box filters

This filter averages out the pixel value as the kernel matrix is denoted as follows:

Applying this filter results in blurring the image. The results are as shown as follows:

In frequency domain analysis of the image, this filter is a low pass filter. The frequency domain analysis is done using Fourier transformation of the image, which is beyond the scope of this introduction. We can see on changing the kernel size, the image gets more and more blurred:

As we increase the size of the kernel, we can observe that resulting image gets more blurred. This is due to averaging out of peak values in the small neighborhood where the kernel is applied. The result for applying kernel of size 20 x 20 can be seen in the following image:

 

However, if we use a very small filter of size (3, 3) there is negligible effect on the output, due to the fact that the kernel size is quite small compared to the photo size. In most applications, kernel size is heuristically set according to image size:

The complete code to generate box filtered photos is as follows:

def plot_cv_img(input_image, output_image): 
"""
Converts an image from BGR to RGB and plots
"""

fig, ax = plt.subplots(nrows=1, ncols=2)

ax[0].imshow(cv2.cvtColor(input_image, cv2.COLOR_BGR2RGB))
ax[0].set_title('Input Image')
ax[0].axis('off')

ax[1].imshow(cv2.cvtColor(output_image, cv2.COLOR_BGR2RGB))
ax[1].set_title('Box Filter (5,5)')
ax[1].axis('off')
plt.show()


def main():
# read an image
img = cv2.imread('../figures/flower.png')


# To try different kernel, change size here.
kernel_size = (5,5)

# opencv has implementation for kernel based box blurring
blur = cv2.blur(img,kernel_size)

# Do plot
plot_cv_img(img, blur)

if __name__ == '__main__':
main()
主站蜘蛛池模板: 景宁| 会东县| 绥棱县| 柳河县| 潮州市| 炎陵县| 抚顺市| 临洮县| 雷州市| 沅陵县| 田东县| 辽阳市| 景洪市| 黄梅县| 西青区| 台前县| 岐山县| 高淳县| 民乐县| 靖安县| 玛纳斯县| 黑河市| 资源县| 夏河县| 新平| 都匀市| 苏尼特左旗| 西平县| 中山市| 巍山| 鄂伦春自治旗| 平果县| 寻甸| 焉耆| 晋宁县| 新闻| 元江| 石门县| 腾冲县| 光泽县| 两当县|