0
点赞
收藏
分享

微信扫一扫

手动实现伽马校正(python)


对​​lena.jpg​​进行伽马校正( c = 1 c=1 c=1, g = 2.2 g=2.2 g=2.2)!

伽马校正用来对照相机等电子设备传感器的非线性光电转换特性进行校正。如果图像原样显示在显示器等上,画面就会显得很暗。伽马校正通过预先增大 RGB 的值来排除显示器的影响,达到对图像修正的目的。

由于下式引起非线性变换,在该式中, x x x被归一化,限定在 [ 0 , 1 ] [0,1] [0,1]范围内。 c c c是常数, g g g为伽马变量(通常取 2.2 2.2 2.2):

x ′ = c   I i n g x' = c\ {I_{in}}^ g x′=c Iin​g

因此,使用下面的式子进行伽马校正:

I o u t = 1 c   I i n 1 g I_{out} ={\frac{1}{c}\ I_{in}} ^ {\frac{1}{g}} Iout​=c1​ Iin​g1​

# -*- coding: utf-8 -*-
"""
Created on Sat Jul 12 14:53:28 2020

@author: 陨星落云
"""
import imageio
import numpy as np
import matplotlib.pylab as plt

def GammaCorrection(img,c=1.0,g=2.2):

# 伽马校正
out = (np.power(img/255, 1.0/g)/c)*255

return out.astype(np.uint8)

if __name__ == "__main__":

# 读取图像
img = imageio.imread("lena.jpg")

# 伽马校正
imageio.imsave("GammaCorrection.jpg",GammaCorrection(img))

# 显示图像
plt.figure(figsize=(10,8))
plt.subplot(121)
plt.imshow(img)
plt.subplot(122)
plt.imshow(GammaCorrection(img))
plt.show()

结果:

手动实现伽马校正(python)_伽马校正



举报

相关推荐

0 条评论