第5章 Python 数字图像处理(DIP) - 图像复原与重建2 - 瑞利噪声
生活随笔
收集整理的這篇文章主要介紹了
第5章 Python 数字图像处理(DIP) - 图像复原与重建2 - 瑞利噪声
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
標題
- 瑞利噪聲
瑞利噪聲
瑞利噪聲的PDF為
P(z)={2b(z?a)e?(z?a)2/b,z≥a0,z<a(5.4)P(z) = \begin{cases} \frac{2}{b}(z-a)e^{-(z-a)^2/b}, & z \ge a \\ 0, & z < a\end{cases} \tag{5.4}P(z)={b2?(z?a)e?(z?a)2/b,0,?z≥az<a?(5.4)
均值和方差為
zˉ=a+πb/4(5.5)\bar{z} = a + \sqrt{\pi b /4} \tag{5.5}zˉ=a+πb/4?(5.5)
σ2=b(4?π)4(5.6)\sigma^2 = \frac{b(4-\pi)}{4} \tag{5.6}σ2=4b(4?π)?(5.6)
更正下面代碼,如果之前已經復制的,也請更正
def add_rayleigh_noise(img, a=3):"""add rayleigh noise for imageparam: img: input image, dtype=uint8param: mean: noise meanparam: sigma: noise sigmareturn: image_out: image with rayleigh noise"""# image = np.array(img/255, dtype=float) # 這是有錯誤的,將得不到正確的結果,修改如下image = np.array(img, dtype=float)# ============== numpy.random.rayleigh======noise = np.random.rayleigh(a, size=image.shape)image_out = image + noiseimage_out = np.uint8(normalize(image_out)*255)return image_out # 瑞利PDF a = 10 b = 400 z = np.linspace(0, 255, 200)z_ = a + np.sqrt(np.pi*b/4) sigma = (b * (4 - np.pi)) / 4 peak_x = a + np.sqrt(b/2) peak_y = 0.607 * np.sqrt(2/b)print(f"z_ -> {z_}, sigma^2 -> {sigma}")rayleigh = rayleigh_pdf(z, a=a, b=b)plt.figure(figsize=(9, 6)) plt.plot(z, rayleigh), #plt.xticks([a, peak_x]), plt.yticks([0, peak_y]) plt.show() z_ -> 27.72453850905516, sigma^2 -> 85.84073464102069 # 瑞利噪聲 img_ori = cv2.imread("DIP_Figures/DIP3E_Original_Images_CH05/Fig0503 (original_pattern).tif", 0) # img_ori = np.ones((512, 512)) * 128 img_rayleigh = add_rayleigh_noise(img_ori, a=30)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_rayleigh, 'gray', vmin=0, vmax=255), plt.xticks([]), plt.yticks([])plt.tight_layout() plt.show() hist, bins = np.histogram(img_rayleigh.flatten(), bins=255, range=[0, 255], density=True) bar = plt.bar(bins[:-2], hist[:-1])總結
以上是生活随笔為你收集整理的第5章 Python 数字图像处理(DIP) - 图像复原与重建2 - 瑞利噪声的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 3.配置阿里云镜像加速
- 下一篇: java编程基础 | 练习题