幂律(伽马)变换

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

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

其中,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()

原图:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乐亦亦乐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值