第5章 Python 数字图像处理(DIP) - 图像复原与重建5 - 均匀噪声
生活随笔
收集整理的這篇文章主要介紹了
第5章 Python 数字图像处理(DIP) - 图像复原与重建5 - 均匀噪声
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
標題
- 均勻噪聲
均勻噪聲
均勻噪聲的PDF為
P(z)={1b?a,a≤z≤b0,other(5.13)P(z) = \begin{cases}\frac{1}{b-a}, & a\leq z \leq b \\ 0, & \text{other}\end{cases} \tag{5.13}P(z)={b?a1?,0,?a≤z≤bother?(5.13)
均值和方差為
zˉ=a+b2(5.14)\bar{z} = \frac{a + b}{2} \tag{5.14}zˉ=2a+b?(5.14)
σ2=(b?a)212(5.15)\sigma^2 = \frac{(b - a)^2}{12} \tag{5.15}σ2=12(b?a)2?(5.15)
更正下面代碼,如果之前已經復制的,也請更正
def add_average_noise(img, mean=0, sigma=800):"""add average noise for imageparam: img: input image, dtype=uint8param: mean: noise meanparam: sigma: noise sigmareturn: image_out: image with average noise"""# image = np.array(img/255, dtype=float) # 這是有錯誤的,將得不到正確的結果,修改如下image = np.array(img, dtype=float)a = 2 * mean - np.sqrt(12 * sigma)b = 2 * mean + np.sqrt(12 * sigma)noise = np.random.uniform(a, b, image.shape)image_out = image + noiseimage_out = np.uint8(normalize(image_out)*255)return image_out # 均勻噪聲 a = 8 b = 9 z = np.linspace(0, 10, 200)z_ = (a + b) / 2 sigma = (b - a)**2 / 12print(f"z_ -> {z_}, sigma -> {sigma}")mean = average_pdf(z, a=a, b=b)plt.figure(figsize=(9, 6)) plt.plot(z, mean) plt.show() z_ -> 8.5, sigma -> 0.08333333333333333 # 均勻噪聲 # img_ori = np.ones((512, 512)) * 128 img_ori = cv2.imread("DIP_Figures/DIP3E_Original_Images_CH05/Fig0503 (original_pattern).tif", 0) img_average = add_average_noise(img_ori, mean=10, sigma=150)plt.figure(figsize=(9, 6)) plt.subplot(121), plt.imshow(img_ori, 'gray', vmin=0, vmax=255), plt.xticks([]), plt.yticks([]) plt.subplot(122), plt.imshow(img_average, 'gray', vmin=0, vmax=255), plt.xticks([]), plt.yticks([])plt.tight_layout() plt.show() hist, bins = np.histogram(img_average.flatten(), bins=255, range=[0, 255], density=True) bar = plt.bar(bins[:-1], hist[:])總結
以上是生活随笔為你收集整理的第5章 Python 数字图像处理(DIP) - 图像复原与重建5 - 均匀噪声的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【基于机器视觉与深度学习的人机对弈机器人
- 下一篇: 第5章 Python 数字图像处理(DI