第5章 Python 数字图像处理(DIP) - 图像复原与重建3 - 爱尔兰(伽马)噪声
生活随笔
收集整理的這篇文章主要介紹了
第5章 Python 数字图像处理(DIP) - 图像复原与重建3 - 爱尔兰(伽马)噪声
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
標題
- 愛爾蘭(伽馬)噪聲
愛爾蘭(伽馬)噪聲
愛爾蘭噪聲的PDF是
P(z)={abzb?1(b?1)!e?az,z≥00,z<0(5.7)P(z) = \begin{cases} \frac{a^bz^{b-1}}{(b-1)!}e^{-az}, & z\geq 0 \\ 0, & z < 0 \end{cases} \tag{5.7}P(z)={(b?1)!abzb?1?e?az,0,?z≥0z<0?(5.7)
a>ba > ba>b, bbb是一個正整數,"!"是階乘
均值和方差為
zˉ=ba(5.8)\bar{z} = \frac{b}{a} \tag{5.8}zˉ=ab?(5.8)
σ2=ba2(5.9)\sigma^2 = \frac{b}{a^2} \tag{5.9}σ2=a2b?(5.9)
僅當分母 為伽馬函數Γ(b)\Gamma(b)Γ(b)時這稱為伽馬密度
當b=1b=1b=1時,為指數噪聲
def ireland_pdf(z, a=2, b=1):"""create ireland PDF, math $$P(z) = \begin{cases} \frac{a^bz^{b-1}}{(b-1)!}e^{-az}, & z\geq 0 \\ 0, & z < 0 \end{cases}$$param: z: input grayscale value of iamgeparam: a: float, a > bparam: b: uint, """ireland = (a**b * z**(b-1) / np.math.factorial(b - 1)) * np.exp(- a *z)ireland = np.where(z >= 0, ireland, 0)return ireland更正下面代碼,如果之前已經復制的,也請更正
def add_gamma_noise(img, scale=1):"""add gamma noise for imageparam: img: input image, dtype=uint8param: mean: noise meanparam: sigma: noise sigmareturn: image_out: image with gamma noise"""# image = np.array(img/255, dtype=float) # 這是有錯誤的,將得不到正確的結果,修改如下image = np.array(img, dtype=float)noise = np.random.gamma(shape=1, scale=scale, size=image.shape)image_out = image + noiseimage_out = np.uint8(normalize(image_out)*255)return image_out # 愛爾蘭(伽馬)噪聲 a = 2.1 b = 2 z = np.linspace(0, 10, 200)z_ = b / a sigma = b / a**2print(f"z_ -> {z_}, sigma -> {sigma}")ireland = ireland_pdf(z, a=a, b=b)plt.figure(figsize=(9, 6)) plt.plot(z, ireland) plt.show() z_ -> 0.9523809523809523, sigma -> 0.4535147392290249 # 伽馬噪聲 img_ori = cv2.imread("DIP_Figures/DIP3E_Original_Images_CH05/Fig0503 (original_pattern).tif", 0) # img_ori = np.ones((512, 512)) * 128 img_gamma = add_gamma_noise(img_ori, scale=20)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_gamma, 'gray', vmin=0, vmax=255), plt.xticks([]), plt.yticks([])plt.tight_layout() plt.show() hist, bins = np.histogram(img_gamma.flatten(), bins=255, range=[0, 255], density=True) bar = plt.bar(bins[:-1], hist[:])總結
以上是生活随笔為你收集整理的第5章 Python 数字图像处理(DIP) - 图像复原与重建3 - 爱尔兰(伽马)噪声的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java编程基础 | 练习题
- 下一篇: j计算机实验室安全操作规范,实验室安全操