From a6d562984bed809b0f454e593c1bfb74202c9319 Mon Sep 17 00:00:00 2001 From: Cx330 <1487537121@qq.com> Date: Sun, 13 Apr 2025 12:19:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E9=80=82=E5=BA=94=E4=B8=AD=E5=80=BC?= =?UTF-8?q?=E6=BB=A4=E6=B3=A2=EF=BC=88=E6=94=AF=E6=8C=81=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=A4=A7=E5=B0=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pepper_and_salt.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pepper_and_salt.py b/pepper_and_salt.py index 293f0fe..cf9180e 100644 --- a/pepper_and_salt.py +++ b/pepper_and_salt.py @@ -7,17 +7,34 @@ from adaptive_median_filter import adaptive_median_filter #读取照片 image_saltandpep = cv2.imread("file/circuitboard-saltandpep.tif", cv2.IMREAD_GRAYSCALE) -# 自适应中值滤波 -image_saltandpep2 = adaptive_median_filter(image_saltandpep) +#设置窗口大小 +kernel_size_windows1 = 3 +kernel_size_windows2 = 7 +kernel_size_windows3 = 15 -plt.subplot(1,2,1) +# 自适应中值滤波 +image_saltandpep2 = adaptive_median_filter(image_saltandpep,kernel_size_windows1) +image_saltandpep3 = adaptive_median_filter(image_saltandpep,kernel_size_windows2) +image_saltandpep4 = adaptive_median_filter(image_saltandpep,kernel_size_windows3) + +plt.subplot(2,2,1) plt.imshow(image_saltandpep, cmap='gray') plt.title('3.胡椒噪声和盐噪声') plt.axis('off') -plt.subplot(1,2,2) +plt.subplot(2,2,2) plt.imshow(image_saltandpep2, cmap='gray') -plt.title('3.自适应中值滤波_胡椒噪声和盐噪声') +plt.title('3.自适应中值滤波_胡椒噪声和盐噪声(窗口大小3)') +plt.axis('off') + +plt.subplot(2,2,3) +plt.imshow(image_saltandpep3, cmap='gray') +plt.title('3.自适应中值滤波_胡椒噪声和盐噪声(窗口大小7)') +plt.axis('off') + +plt.subplot(2,2,4) +plt.imshow(image_saltandpep4, cmap='gray') +plt.title('3.自适应中值滤波_胡椒噪声和盐噪声(窗口大小15)') plt.axis('off') plt.tight_layout()