图像Gamma变换 您所在的位置:网站首页 伽马函数渐近线 图像Gamma变换

图像Gamma变换

2024-07-04 08:31| 来源: 网络整理| 查看: 265

图像Gamma变换-图像增强 原理代码结果亮度斜坡图像自然图像进行伽马变换 参考

原理

幂函数的基本形式为: s = c × r Γ s = c \times r ^ \Gamma s=c×rΓ 其中 c 和 Γ \Gamma Γ表示正常数,r表示输入的灰度值,当c=1时不同的 Γ \Gamma Γ值对应的s曲线如下图所示。 当 Γ < 1 \Gamma1 Γ>1对图像的高亮部分有抑制作用。 gamma

代码 import numpy as np import matplotlib.pyplot as plt from skimage import io def gamma_transform(image, th1, th2, gamma1, gamma2): if gamma1 == gamma2: image1 = np.power(image, gamma1) else: if image.ndim == 3: c, r, d = image.shape y = image[:,:,0]*0.299+image[:,:,1]*0.587+image[:,:,2]*0.114 image1 = np.zeros((c, r, d)) for i in range(c): for j in range(r): if y[i,j] = th2: image1[i,j,:] = np.power(image[i, j, :], gamma2) else: image1[i,j,:] = image[i,j,:] elif image.ndim == 2: c, r = image.shape y = image image1 = np.zeros((c, r)) for i in range(c): for j in range(r): if y[i,j] = th2: image1[i,j] = np.power(image[i, j], gamma2) else: image1[i,j] = image[i,j] return image1 path = 'D:/2_project/0_test/1.jpg' I = io.imread(path) I1 = I/255.0 image1 = gamma_transform(I1, 0, 0, 0.4, 0.4) image2 = gamma_transform(I1, 0, 0, 2, 2) image3 = gamma_transform(I1, 0.5, 0.5, 0.4, 2) image4 = gamma_transform(I1, 0.3, 0.75, 0.4, 2) plt.figure() plt.subplot(221) plt.imshow(image1) plt.axis('off') plt.subplot(222) plt.imshow(image2) plt.axis('off') plt.subplot(223) plt.imshow(image3) plt.axis('off') plt.subplot(224) plt.imshow(image4) plt.axis('off') ##灰度范围测试 a = np.zeros((100, 256)) for i in range(100): for j in range(256): a[i,j] = j b = a/255.0 b1 = gamma_transform(b, 0, 0, 0.4, 0.4) b2 = gamma_transform(b, 0, 0, 2, 2) b3 = gamma_transform(b, 0.5, 0.5, 0.4, 2) b4 = gamma_transform(b, 0.3, 0.75, 0.5, 2) plt.figure() plt.subplot(221) plt.imshow(b1, 'gray') plt.axis('off') plt.subplot(222) plt.imshow(b2, 'gray') plt.axis('off') plt.subplot(223) plt.imshow(b3, 'gray') plt.axis('off') plt.subplot(224) plt.imshow(b4, 'gray') plt.axis('off') 结果 亮度斜坡图像

生成0-255范围的灰度斜坡图像,如下图所示 1 对其进行 Γ = 0.1 \Gamma=0.1 Γ=0.1变换,可以从中看出对暗区的部分有提亮作用 2 对其进行 Γ = 2 \Gamma=2 Γ=2变换,可以从中看出对高亮的部分有压制作用 3 对不同阶段范围的灰度进行不同的 Γ \Gamma Γ处理,会出现分层的情况: 当灰度值<0.5时, Γ = 0.1 \Gamma=0.1 Γ=0.1,当灰度值>0.5时, Γ = 2 \Gamma=2 Γ=2,得到的图像如下图所示: 4 当灰度值<0.25时, Γ = 0.1 \Gamma=0.1 Γ=0.1,当灰度值>0.75时, Γ = 2 \Gamma=2 Γ=2,得到的图像如下图所示: 5

自然图像进行伽马变换

一张自然图像如下所示: 10 对其进行 Γ = 0.1 \Gamma=0.1 Γ=0.1变换,可以从中看出对暗区的部分有提亮作用 11

对其进行 Γ = 2 \Gamma=2 Γ=2变换,可以从中看出对高亮的部分有压制作用 12 对不同阶段范围的灰度进行不同的 Γ \Gamma Γ处理,会出现分层的情况: 当灰度值<0.5时, Γ = 0.1 \Gamma=0.1 Γ=0.1,当灰度值>0.5时, Γ = 2 \Gamma=2 Γ=2,得到的图像如下图所示: 13 当灰度值<0.25时, Γ = 0.1 \Gamma=0.1 Γ=0.1,当灰度值>0.75时, Γ = 2 \Gamma=2 Γ=2,得到的图像如下图所示: 14

参考

冈萨雷斯数字图像处理第三版



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有