Fourth commit

This commit is contained in:
lan daiqing
2022-07-27 20:41:38 +08:00
parent 079dd34037
commit 3d78b6edb3
11 changed files with 623 additions and 105 deletions

View File

@@ -6,34 +6,45 @@
# @Software: PyCharm
'''
gamma矫正公式
f(x)=xγ
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):
# 定义伽马矫正函数
def gammaCorrect(filePath, val):
'''
:param filePath: 图片路径
:param val: 伽马值
:return: 图片
'''
# 获取图片
im = Image.open(filePath)
img = np.array(im)
img = np.array(im) # 图片转矩阵
img1 = np.power(img / float(np.max(img)), 1 / 1.5)
img2 = np.power(img / float(np.max(img)), val)
# 伽马函数使用
img1 = np.power(img / float(np.max(img)), 1 / 1.5) # gamma值为1/1.5
img2 = np.power(img / float(np.max(img)), val) # 自定义gamma值
# 多图合并
plt.subplot(131)
plt.imshow(img)
plt.title("origin")
plt.title("origin") # 展示原图
plt.subplot(132)
plt.imshow(img1)
plt.title("gammar=1/1.5")
plt.title("gammar=1/1.5") # 展示gamma =1/1.5
plt.subplot(133)
plt.imshow(img2)
plt.title("user-defined")
plt.title("user-defined") # 展示自定义 gammat Image
plt.show()
# 图片保存
Image.fromarray(np.uint8(img2)).save(root + 'picture10' + '.jpg')
return img2