import cv2
input_imgfn="tobrighten.jpg"
output_imgfn="brightened.jpg"
def change_brightness(img, value=30):
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
v = cv2.add(v,value)
v[v > 255] = 255
v[v < 0] = 0
final_hsv = cv2.merge((h, s, v))
img = cv2.cvtColor(final_hsv, cv2.COLOR_HSV2BGR)
return img
img = cv2.imread(input_imgfn) #load rgb image
img = change_brightness(img, value=90) #increases
#img = change_brightness(img, value=-30) #decreases
cv2.imwrite(output_imgfn, img)
Like this:
Like Loading...