在gimp里面有曝光的功能
简单看了一下源码,看起来比较简单,使用python简单的实现了一下:
import numpy as np
import cv2
def exposure(img_input, black_level=0, exposure_negated=0.0):
img_input = img_input.astype(np.float32)
assert -0.1 <= black_level <= 0.1
assert -10.0 <= exposure_negated <= 10.0
white = pow(2, -exposure_negated)
diff = max(white - black_level, 0.000001)
gain = 1.0 / diff
img_output = (img_input - black_level)*gain
return img_output
if __name__ == '__main__':
img = cv2.imread('tmp/50.jpg')
exposure_negateds = [-2.5, -1.0, -0.5, 0.5, 1.0, 2.5]
for exposure_negated in exposure_negateds:
res_out = exposure(img, black_level=0, exposure_negated=exposure_negated)
cv2.imwrite('tmp/50_exposure_{}.jpg'.format(exposure_negated), res_out)
原图
0.5曝光
-0.5曝光
1.0曝光
-1.0曝光
2.5曝光
-2.5曝光