如何使用cv.boxFilter()使用python在openCV中过滤20%的盐和胡椒图像?

时间:2019-04-09 02:48:31

标签: python opencv

当我运行程序时,所有其他过滤器似乎都在工作,但是boxFilter()函数显示图像变黑了。我不知道为什么所有其他的中值高斯滤波器图像将其显示为灰度图像,并且似乎正在从图像中滤除盐和胡椒粉噪声。而且我也不确定如何正确使用这些功能,比较哪种滤镜最适合20%的盐和胡椒粉图像?

import cv2 as cv
import numpy as np
import skimage.util.noise as noise
import scipy.ndimage as ndi
import skimage.io as io
import skimage.color as co

img = cv.imread('opencv-logo.jpg',0)

# Add 20 percent salt and peppernoise
spImg = noise.random_noise(img, mode='s&p', amount=0.2)
cv.imshow('Salt and Pepper image', spImg)

# Box Filter
box = cv.boxFilter(spImg, 0,(5,5), spImg, (-1,-1), False, cv.BORDER_DEFAULT)
cv.imshow('Box Filter', box)

# Median Filter
median = ndi.median_filter(spImg,5)
cv.imshow('Median Filter', median)

# Gaussian Filter
blur = cv.GaussianBlur(spImg,(5,5),0)
cv.imshow('Gaussian Filter', blur) 

cv.waitKey(0)
cv.destroyAllWindows()
cv.waitKey(1)  # If I dont have this line then the window won't close for me on my mac when I enter a key

0 个答案:

没有答案