均值模糊 中值模糊 自定义模糊(卷积方法) 高斯模糊
均值模糊:
cv2.blur(image,(size,size))
image 图像
size 卷积核大小
返回值 处理后图像
中值模糊
cv2.medianBlur(image,size)
image 待处理图像
size 方形卷积核边长
返回值 处理后图像
自定义模糊
cv2.filter2D(image, ddepth=-1, kernel)
2维卷积
image待处理图像
ddepth 表示处理图像深度 当值为-1是表示原图像深度
kernel 为卷积核 需要自定义2维卷积核
返回值 处理后图像
高斯模糊
C++: void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT )
src 待处理图像
dst为处理后图像
ksize为卷积核大小
sigmaX x方向标准差 Y类似
borderType像素外插策咯(待理解)
模糊方法可以处理图像噪点
高斯早点生成代码如下:
def gaussian_noise(image): # 手写高斯噪声
h, w, chan = image.shape
for row in range(h):
for col in range(w):
noise = np.random.normal(0, 20, 3).astype(np.uint8)
image[row, col, :] += noise #这一步需要修正范围0~255
return image