1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 第3章 Python 数字图像处理(DIP) - 灰度变换与空间滤波3 -幂律变换 伽马变换

第3章 Python 数字图像处理(DIP) - 灰度变换与空间滤波3 -幂律变换 伽马变换

时间:2024-06-11 16:27:08

相关推荐

第3章 Python 数字图像处理(DIP) - 灰度变换与空间滤波3 -幂律变换 伽马变换

目录

幂律(伽马)变换

幂律(伽马)变换

s=crγ(3.5)s = c r^{\gamma} \tag{3.5}s=crγ(3.5)

c和γc和\gammac和γ是正常数。考虑到偏移(即输入为0时的一个可度量输出),可改写为s=c(r+ϵ)γs = c (r + \epsilon) ^{\gamma}s=c(r+ϵ)γ

用于获取、打印和显示图像的许多设备的响应遵守幂律。用于校正这些幂律响应现象的处理称为伽马校正伽马编码

我们感兴趣的是曲线的形状,而不是它们的相对值

# 伽马变换不同伽马值的图像,为了图像好看,缩放到相同的数值范围x = np.arange(0, 256, 1)epsilon = 1e-5gammas = [0.04, 0.10, 0.2, 0.40, 0.67, 1, 1.5, 2.5, 5.0, 10, 25]fig = plt.figure(figsize=(6, 6))ax = fig.gca()for gamma in gammas:n_power = normalize(np.power(x + epsilon, gamma)) * 255ax.plot(x, n_power, label='$\gamma = {}$'.format(gamma))ax.legend(loc='best')plt.ylim([0, 255])plt.xlim([0, 255])plt.show()

def gamma_transform(img, c, gamma):"""gamma transform 2d grayscale image, convert uint image to floatparam: input img: input grayscale image param: input c: scale of the transformparam: input gamma: gamma value of the transoform"""img= img.astype(float) #先要把图像转换成为float,不然结果点不太相同epsilon = 1e-5#非常小的值以防出现除0的情况img_dst = np.zeros(img.shape[:2], dtype=np.float)img_dst = c * np.power(img + epsilon, gamma)img_dst = np.uint8(normalize(img_dst) * 255)return img_dst

# 幂律(伽马)变换1img = cv2.imread('DIP_Figures/DIP3E_Original_Images_CH03/Fig0308(a)(fractured_spine).tif', 0)c = 1gammas = [1.0, 0.04, 0.1, 0.3, 0.2, 0.4, 0.67, 0.9, 1.5, 2.5, 5, 10]gama_len = len(gammas)fig = plt.figure(figsize=(15, 26))for i in range(gama_len):ax = fig.add_subplot(4, 3, i+1, xticks=[], yticks=[])img_gamma= gamma_transform(img, c, gammas[i])ax.imshow(img_gamma, cmap='gray')if gammas[i] == 1.0:ax.set_title("Original")else:ax.set_title(f"$\gamma={gammas[i]}$")plt.tight_layout()plt.show()

# 幂律(伽马)变换2img = cv2.imread('DIP_Figures/DIP3E_Original_Images_CH03/Fig0309(a)(washed_out_aerial_image).tif', 0)c = 1gammas = [1.0, 0.1, 0.3, 0.2, 0.4, 0.67, 0.9, 1.5, 3, 4, 5, 10]gama_len = len(gammas)fig = plt.figure(figsize=(15, 21))for i in range(gama_len):ax = fig.add_subplot(4, 3, i+1, xticks=[], yticks=[])img_gamma= gamma_transform(img, c, gammas[i])ax.imshow(img_gamma, cmap='gray')if gammas[i] == 1.0:ax.set_title("Original")else:ax.set_title(f"$\gamma={gammas[i]}$")plt.tight_layout()plt.show()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。