标题
- 指数噪声
指数噪声
指数噪声的PDF为
P(z)={ae−az,z≥00,z<0(5.10)P(z) = \begin{cases} ae^{-az}, & z\geq 0 \\ 0, & z < 0 \end{cases} \tag{5.10}P(z)={ae−az,0,z≥0z<0(5.10)
均值和方差为
zˉ=1a(5.11)\bar{z} = \frac{1}{a} \tag{5.11}zˉ=a1(5.11)
σ2=1a2(5.12)\sigma^2 = \frac{1}{a^2} \tag{5.12}σ2=a21(5.12)
def exponential_pdf(z, a=1):"""create exponential PDF, math $$P(z) = \begin{cases} ae^{-az}, & z\geq 0 \\ 0, & z < 0 \end{cases}$$param: z: input grayscale value of iamgeparam: a: float,"""exp = a * np.exp(-a * z)exp = np.where(z >= 0, exp, 0)return exp
更正下面代码,如果之前已经复制的,也请更正
def add_exponent_noise(img, scale=1.0):"""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.exponential(scale=scale, size=image.shape)image_out = image + noiseimage_out = np.uint8(normalize(image_out)*255)return image_out
# 指数噪声
a = 0.5
z = np.linspace(0, 10, 200)z_ = 1 / a
sigma = 1 / a**2print(f"z_ -> {z_}, sigma -> {sigma}")exponet = exponential_pdf(z, a=a)plt.figure(figsize=(9, 6))
plt.plot(z, exponet)
plt.show()
z_ -> 2.0, sigma -> 4.0
# 指数噪声
img_ori = cv2.imread("DIP_Figures/DIP3E_Original_Images_CH05/Fig0503 (original_pattern).tif", 0)
# img_ori = np.ones((512, 512)) * 128
img_exponent = add_exponent_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_exponent, 'gray', vmin=0, vmax=255), plt.xticks([]), plt.yticks([])plt.tight_layout()
plt.show()
hist, bins = np.histogram(img_exponent.flatten(), bins=255, range=[0, 255], density=True)
bar = plt.bar(bins[:-1], hist[:])