标签:des style blog http color strong
Blurs an image using the median filter.
| Parameters: |
|
|---|
The function smoothes an image using the median filter with the
aperture. Each channel of a multi-channel image is processed independently. In-place operation is supported.
中值滤波将图像的每个像素用邻域 (以当前像素为中心的正方形区域)像素的 中值 代替 。与邻域平均法类似,但计算的是中值
# -*- coding: utf-8 -*-
#code:myhaspl@myhaspl.com
#中值滤波
import cv2
import numpy as np
fn="test3.jpg"
myimg=cv2.imread(fn)
img=cv2.cvtColor(myimg,cv2.COLOR_BGR2GRAY)
#加上椒盐噪声
#灰阶范围
w=img.shape[1]
h=img.shape[0]
newimg=np.array(img)
#噪声点数量
noisecount=50000
for k in xrange(0,noisecount):
xi=int(np.random.uniform(0,newimg.shape[1]))
xj=int(np.random.uniform(0,newimg.shape[0]))
newimg[xj,xi]=255
#滤波去噪
lbimg=cv2.medianBlur(newimg,3)
cv2.imshow(‘src‘,newimg)
cv2.imshow(‘dst‘,lbimg)
cv2.waitKey()
cv2.destroyAllWindows()
中值滤波忽略了较高阶灰度和较低阶灰度,直接取中值,因为有效得过滤椒盐噪声
对高斯噪声的滤波
数学之路-python计算实战(17)-机器视觉-滤波去噪(中值滤波),布布扣,bubuko.com
数学之路-python计算实战(17)-机器视觉-滤波去噪(中值滤波)
标签:des style blog http color strong
原文地址:http://blog.csdn.net/myhaspl/article/details/37997977