幂律(伽马)变换

您所在的位置:网站首页 幂指数对图像的影响 幂律(伽马)变换

幂律(伽马)变换

2023-09-02 15:38| 来源: 网络整理| 查看: 265

  伽马变换(幂律变换)是常用的灰度变换,是一种简单的图像增强算法。

伽玛变换的一般表达式为:

其中,r为灰度图像的输入值(原来的灰度值),取值范围为[0,1]。s为经过伽马变换后的灰度输出值。c为灰度缩放系数,通常取1。γ为伽马因子大小。控制了整个变换的缩放程度。

 

 图片来源:【FPGA实现图像的非线性变换:伽玛(幂律)变换 - 咸鱼FPGA - 博客园】

代码:

from PIL import Image as Image import numpy as np import matplotlib.pyplot as plt def gamma_transformation(input_image, c, gamma): ''' 伽马变换 :param input_image: 原图像 :param c: 伽马变换超参数 :param gamma: 伽马值 :return: 伽马变换后的图像 ''' input_image_cp = np.copy(input_image) # 输入图像的副本 output_imgae = c * np.power(input_image_cp, gamma) # 输出图像 return output_imgae path=r'C:\Users\Administrator\Desktop\Pytorch\downsample\gamma\原图.jpg' image = Image.open(path) img=np.array(image)/255.0 r_3=gamma_transformation(img,1,3.0) r_4=gamma_transformation(img,1,4.0) r_5=gamma_transformation(img,1,5.0) # 显示图像 plt.figure() plt.subplot(1,4,1) plt.imshow(img) plt.subplot(1,4,2) plt.imshow(r_3) plt.subplot(1,4,3) plt.imshow(r_4) plt.subplot(1,4,4) plt.imshow(r_5) plt.show()

原图:

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3