找了好多方法都感觉不太适合,自己琢磨写了一套,但是又怀疑有人想到过这种方式了,苦于找不到出处,如果有人知道的,感谢告知一下(可能并没有出处)。
import cv2
import numpy as np
def contrast(img, factor): #0<factor<1为削弱,大于1为增强
img = img**(2.2)
mean = np.mean(img)
img = img-mean
img = img*factor
img = img+mean
img = (np.clip(img,0,1))**(1/2.2)
return img
def luminance(img, factor):
img = img**(2.2)
img = img*factor
img = (np.clip(img,0,1))**(1/2.2)
return img
imgpath = '/Art_012.png'
img = cv2.imread(imgpath, -1)/255
img = luminance(img, 0.5)
#img = contrast(img, 0.5)
cv2.imshow('img', img)
cv2.waitKey()