From bc8a37a471c42399b033decf28151c67d723abbc Mon Sep 17 00:00:00 2001 From: peiszf7yu <3261107288@qq.com> Date: Thu, 21 Jul 2022 20:34:44 +0800 Subject: [PATCH] ADD file via upload --- 空域平滑.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 空域平滑.py 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)