标题
- 估计噪声参数
估计噪声参数
周期噪声的参数通常是通过检测图像的傅里叶谱来估计的。
只能使用由传感器生成的图像时,可由一小片恒定的背景灰度来估计PDF的参数。
来自图像条带的数据的最简单用途是,计算灰度级的均值和方差。考虑由SSS表示的一个条带(子图像),并令PS(zi)P_{S}(z_i)PS(zi),i=0,1,2,…,L−1i = 0, 1, 2, \dots, L-1i=0,1,2,…,L−1表示SSS中的像素灰度的概率估计(归一化直方图值),其中LLL是整数个图像中的可能灰度(对8比特而言,LLL为256)。则均值和方差估计如下:
zˉ=∑i=0L−1ziPS(zi)(5.19)\bar{z} = \sum_{i=0}^{L-1}z_{i}P_{S}(z_{i}) \tag{5.19}zˉ=i=0∑L−1ziPS(zi)(5.19)
σ2=∑i=0L−1(zi−zˉ)2PS(zi)(5.20)\sigma^2 = \sum_{i=0}^{L-1}(z_{i} -\bar{z})^2 P_{S}(z_{i}) \tag{5.20}σ2=i=0∑L−1(zi−zˉ)2PS(zi)(5.20)
直方图的形状确认最接近的PDF匹配。若形状大致为高斯分布的,则均值和方差就是我们所需要的,因为高斯PDF完全由这两个参数规定。对于其它PDF,我们可以使用均值和方差来求解参数aaa和bbb。
对于冲激噪声的处理是不同的,因为需要的估计是黑、白像素出现的实际概率。要获得这个估计,就需要看到黑色像素和白色像素,因此要算出噪声的有意义的直方图,图像中就需要有一个相对恒定的中灰度区域。对应于黑色像素和白色像素的峰值高度是式(5.16)中PpP_pPp和PsP_sPs的估计。
# 一些重要的噪声对应灰度的直方图
img_ori = cv2.imread("DIP_Figures/DIP3E_Original_Images_CH05/Fig0503 (original_pattern).tif", 0)
# 竖图[40:210, 35:60],横图[40:60, 35:220]
img_gauss = add_gaussian_noise(img_ori, mu=0, sigma=0.05)[40:60, 35:220]
img_rayleigh = add_rayleigh_noise(img_ori, a=1)[40:60, 35:220]
img_gamma = add_gamma_noise(img_ori, scale=2)[40:60, 35:220]
img_exponent = add_exponent_noise(img_ori, scale=3)[40:60, 35:220]
img_average = add_average_noise(img_ori, mean=10, sigma=1.5)[40:60, 35:220]ps = 0.05
pp = 0.02
img_salt_pepper = add_salt_pepper(img_ori, ps=ps, pp=pp)[40:60, 35:220]show_list = ['img_gauss', 'img_rayleigh', 'img_gamma', 'img_exponent', 'img_average', 'img_salt_pepper']fig = plt.figure(figsize=(15, 15))for i in range(len(show_list)):if i >= 3:# 显示图像ax = fig.add_subplot(4, 3, i + 3 + 1)ax.imshow(eval(show_list[i]), 'gray'), ax.set_xticks([]), ax.set_yticks([]), ax.set_title(show_list[i].split('_')[-1])# 对应图像的直方图ax = fig.add_subplot(4, 3, i + 1 + 6)hist, bins = np.histogram(eval(show_list[i]).flatten(), bins=255, range=[0, 255], density=True)bar = ax.bar(bins[:-1], hist[:]), ax.set_xticks([]), ax.set_yticks([]),else:# 显示图像ax = fig.add_subplot(4, 3, i + 1)ax.imshow(eval(show_list[i]), 'gray'), ax.set_xticks([]), ax.set_yticks([]), ax.set_title(show_list[i].split('_')[-1])# 对应图像的直方图ax = fig.add_subplot(4, 3, i + 1 + 3)hist, bins = np.histogram(eval(show_list[i]).flatten(), bins=255, range=[0, 255], density=True)bar = ax.bar(bins[:-1], hist[:]), ax.set_xticks([]), ax.set_yticks([]),plt.tight_layout()
plt.show()
# 椒盐噪声的参数估计
hist, bins = np.histogram(img_salt_pepper.flatten(), bins=255, range=[0, 255], density=True)
print(f"Original pp -> {pp:.3f}, ps -> {ps:.3f}")
print(f'Estimate PP -> {hist[0]:.3f}, PS -> {hist[-1]:.3f}')
Original pp -> 0.020, ps -> 0.050
Estimate PP -> 0.018, PS -> 0.050
# 内嵌图像
fig, main_ax = plt.subplots()
hist, bins = np.histogram(img_gauss.flatten(), bins=255, range=[0, 255], density=True)
bar = main_ax.bar(bins[:-1], hist[:]), main_ax.set_xticks([]), main_ax.set_yticks([])inset_ax = fig.add_axes([0.1, 0.3, 0.2, 0.5])
inset_ax.imshow(img_gauss.reshape(185, 20), 'gray'), inset_ax.set_xticks([]), inset_ax.set_yticks([])plt.show()