Python + OpenCV模糊处理(Bluring)
- seuchenrui@126.com
模糊处理在边沿检测和去噪声方面有较为广泛的应用。OpenCV中提供了4种模糊算法,列举如下:
- average
- median
- gaussian
- bilateral
本文将分别采用这4种算法对同一幅图像进行处理,并以图像的形式展现这几种算法之间的差别。
1 average
代码如下
import numpy
import argparse
import cv2
image = cv2.imread('1.jpg')
cv2.imshow("Original", image)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow("Gray", gray)
#[x,y] is the kernel for bluring
#the large kernel becomes, the more blurred imag will appear
#hstack is able to stack multiple images together
#using simple mean to average
blurred = numpy.hstack([
cv2.blur(gray, (3,3)),
cv2.blur(gray, (5,5)),
cv2.blur(gray, (7,7))])
#display two images in a figure