import cv2
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['simHei']
plt.rcParams['axes.unicode_minus'] = False
from adaptive_median_filter import adaptive_median_filter

#读取照片
image_saltandpep = cv2.imread("file/circuitboard-saltandpep.tif", cv2.IMREAD_GRAYSCALE)

#设置窗口大小
kernel_size_windows1 = 3
kernel_size_windows2 = 7
kernel_size_windows3 = 15

# 自适应中值滤波
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(2,2,2)
plt.imshow(image_saltandpep2, cmap='gray')
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()
plt.show()