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

#读取照片
image_pepper = cv2.imread("file/circuitboard-pepper.tif", cv2.IMREAD_GRAYSCALE)
image_salt = cv2.imread("file/circuitboard-salt.tif", cv2.IMREAD_GRAYSCALE)

#反谐波均值滤波_胡椒噪声
kernel_size_pepper = 3    #核的大小
Q_pepper = 1.5    #滤波器阶数
image_pepper2 = contraharmonic_mean_filter(image_pepper,kernel_size_pepper,Q_pepper)

#反谐波均值滤波_盐噪声
kernel_size_salt = 3    #核的大小
Q_salt = -1.5    #滤波器阶数
image_salt2 = contraharmonic_mean_filter(image_salt,kernel_size_salt,Q_salt)

plt.subplot(2,2,1)
plt.imshow(image_pepper, cmap='gray')
plt.title('2.胡椒噪声')
plt.axis('off')

plt.subplot(2,2,2)
plt.imshow(image_pepper2, cmap='gray')
plt.title('2.反谐波均值滤波_胡椒噪声')
plt.axis('off')

plt.subplot(2,2,3)
plt.imshow(image_salt, cmap='gray')
plt.title('2.盐噪声')
plt.axis('off')

plt.subplot(2,2,4)
plt.imshow(image_salt2, cmap='gray')
plt.title('2.反谐波均值滤波_盐噪声')
plt.axis('off')

plt.tight_layout()
plt.show()