- Practical Computer Vision
- Abhinav Dadhich
- 252字
- 2021-06-30 18:54:50
Smoothing a photo
Applying a box filter with hard edges doesn't result in a smooth blur on the output photo.
To improve this, the filter can be made smoother around the edges. One of the popular such filters is a Gaussian filter. This is a non-linear filter which enhances the effect of the center pixel and gradually reduces the effects as the pixel gets farther from the center. Mathematically, a Gaussian function is given as:
where μ is mean and σ is variance.
An example kernel matrix for this kind of filter in a two-dimensional discrete domain is given as follows:
This two-dimensional array is used in normalized form and effect of this filter also depends on its width by changing the kernel width has varying effects on the output as discussed in further section. Applying Gaussian kernel as filter removes high-frequency components which results in removing strong edges and hence a blurred photo:

While this filter performs better blurring than a box filter, the implementation is also quite simple with OpenCV:
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('Gaussian Blurred')
ax[1].axis('off')
plt.show()
def main():
# read an image
img = cv2.imread('../figures/flower.png')
# apply gaussian blur,
# kernel of size 5x5,
# change here for other sizes
kernel_size = (5,5)
# sigma values are same in both direction
blur = cv2.GaussianBlur(img,(5,5),0)
plot_cv_img(img, blur)
if __name__ == '__main__':
main()
- 集成架構(gòu)中型系統(tǒng)
- 電氣自動(dòng)化專業(yè)英語(第3版)
- Google App Inventor
- 21天學(xué)通C#
- 21天學(xué)通Java Web開發(fā)
- Ceph:Designing and Implementing Scalable Storage Systems
- 空間站多臂機(jī)器人運(yùn)動(dòng)控制研究
- 網(wǎng)絡(luò)管理工具實(shí)用詳解
- 軟件構(gòu)件技術(shù)
- 電氣控制與PLC原理及應(yīng)用(歐姆龍機(jī)型)
- 基于RPA技術(shù)財(cái)務(wù)機(jī)器人的應(yīng)用與研究
- 基于Quartus Ⅱ的數(shù)字系統(tǒng)Verilog HDL設(shè)計(jì)實(shí)例詳解
- Learn T-SQL Querying
- AI成“神”之日:人工智能的終極演變
- Photoshop CS6兒童數(shù)碼照片處理達(dá)人秘笈