高斯滤波_模块
去噪声
import cv2
import numpy as np
img = cv2.imread('image11.jpg',1)
cv2.imshow('src',img)
dst = cv2.GaussianBlur(img,(5,5),1.5)
cv2.imshow('dst',dst)
cv2.waitKey(0)
均值滤波_源码
#均值 6*6 1 。 * 【6*6】/36 = mean -》P
import cv2
import numpy as np
img = cv2.imread('image11.jpg',1)
cv2.imshow('src',img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
dst = np.zeros((height,width,3),np.uint8)
for i in range(3,height-3):
for j in range(3,width-3):
sum_b = int(0)
sum_g = int(0)
sum_r = int(0)
for m in range(-3,3):#-3 -2 -1 0 1 2
for n in range(-3,3):
(b,g,r) = img[i+m,j+n]
sum_b = sum_b+int(b)
sum_g = sum_g+int(g)
sum_r = sum_r+int(r)
b = np.uint8(sum_b/36)
g = np.uint8(sum_g/36)
r = np.uint8(sum_r/36)
dst[i,j] = (b,g,r)
cv2.imshow('dst',dst)
cv2.waitKey(0)
网友评论