pythonpictureanalysis/GammaCorrection.py
2022-07-26 21:27:11 +08:00

40 lines
882 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- 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