diff --git a/空域平滑.py b/空域平滑.py new file mode 100644 index 0000000..dcd3d59 --- /dev/null +++ b/空域平滑.py @@ -0,0 +1,66 @@ +import cv2 +import numpy as np +import matplotlib.pyplot as plt + #当使用的平滑模板尺寸增大时,对噪声的消除效果有所增强, + #但是图像更模糊,可视细节逐渐减少,运算量逐步增大 + + +#加椒盐噪声的函数 +def saltPepper(image, salt, pepper): + height = image.shape[0] + width = image.shape[1] + pertotal = salt + pepper #总噪声占比 + noiseImage = image.copy() + noiseNum = int(pertotal * height * width) + for i in range(noiseNum): + rows = np.random.randint(0, height-1) + cols = np.random.randint(0,width-1) + if(np.random.randint(0,100)