opencv image blur image smoothing

Smoothed image (image blur):

    An image and a low-pass filter convolution, image smoothing effect can be achieved, i.e. image blur. Smoothing operation will generally remove high frequency information (noise, edges) from the image. So after image smoothing, image edge tend to be fuzzy (last bilateral fuzzy basic technique described in this article does not blur the image edge). Opencv offers a variety of image smoothing technology, also known as image blurring technology.


1. Average blur

# kernel size is 5*5

blur = cv.blur(img,(5,5))


2. Gaussian blur

# Kernel size is 5 * 5,0: standard deviation stars based on nuclear size

blur = cv.GaussianBlur(img,(5,5),0)


3. Median blur

# kernel size is 5*5

median = cv.medianBlur(img,5)


4. Bilateral blur

# cv.bilateralFilter is highly effective in noise removal while keeping edges sharp

blur = cv.bilateralFilter(img,9,75,75)


Experiment code:

 1 import cv2 as cv
 2 
 3 import numpy as np
 4 
 5 from matplotlib import pyplot as plt
 6 
 7 image1 = cv.imread('../paojie_sp2.jpg')
 8 
 9 avg_img = cv.blur(image1,(5,5))
10 
11 gau_img = cv.GaussianBlur(image1,(5,5),0)
12 
13 med_img = cv.medianBlur(image1,5)
14 
15 bil_img = cv.bilateralFilter(image1,9,75,75)
16 
17 plt.figure(1)
18 
19 plt.subplot (231), plt.imshow (image1), plt.title ( ' Original ' ), plt.axis ( ' off ' )
 20  
21 plt.subplot (232), plt.imshow (avg_img), Plt. title ( ' Average Blur ' ), plt.axis ( ' off ' )
 22  
23 plt.subplot (233), plt.imshow (gau_img), plt.title ( ' Gaussian Blur ' ), plt.axis ( ' off ' )
 24  
25 plt.subplot (234), plt.imshow (med_img), plt.title ( ' Median Blur ' ), plt.axis ( 'off')
26 
27 plt.subplot(235),plt.imshow(bil_img),plt.title('Bilateral Blur'),plt.axis('off')
28 
29 plt.show()

 


The results:


The output smoothing process various image ↑

 

Guess you like

Origin www.cnblogs.com/wojianxin/p/12548624.html