40 lines
882 B
Python
40 lines
882 B
Python
# -*- coding: utf-8 -*-
|
||
# @Time : 2022-7-26 0026 11:41
|
||
# @Author : Qing
|
||
# @Email : derighoid@gmail.com
|
||
# @File : GammaCorrection.py
|
||
# @Software: PyCharm
|
||
'''
|
||
gamma矫正公式:
|
||
f(x)=xγ
|
||
即输出是输入的幂函数,指数为γ.
|
||
'''
|
||
import matplotlib.pyplot as plt
|
||
import numpy as np
|
||
from PIL import Image
|
||
|
||
root = "E:\\桌面\\Python_Picture_Analysis\\data\\"
|
||
|
||
|
||
def gammaCorrect(filePath,val):
|
||
im = Image.open(filePath)
|
||
img = np.array(im)
|
||
|
||
img1 = np.power(img / float(np.max(img)), 1 / 1.5)
|
||
img2 = np.power(img / float(np.max(img)), val)
|
||
|
||
plt.subplot(131)
|
||
plt.imshow(img)
|
||
plt.title("origin")
|
||
plt.subplot(132)
|
||
plt.imshow(img1)
|
||
plt.title("gammar=1/1.5")
|
||
plt.subplot(133)
|
||
plt.imshow(img2)
|
||
plt.title("user-defined")
|
||
plt.show()
|
||
Image.fromarray(np.uint8(img2)).save(root + 'picture10' + '.jpg')
|
||
return img2
|
||
|
||
|