Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def apply_brightness_contrast(input_img, brightness=0, contrast=0):
- if brightness != 0:
- if brightness > 0:
- shadow = brightness
- highlight = 255
- else:
- shadow = 0
- highlight = 255 + brightness
- alpha_b = (highlight - shadow) / 255
- gamma_b = shadow
- buf = cv.addWeighted(input_img, alpha_b, input_img, 0, gamma_b)
- else:
- buf = input_img.copy()
- if contrast != 0:
- f = 131 * (contrast + 127) / (127 * (131 - contrast))
- alpha_c = f
- gamma_c = 127 * (1 - f)
- buf = cv.addWeighted(buf, alpha_c, buf, 0, gamma_c)
- return buf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement