Advertisement
Altair200333

Untitled

Sep 17th, 2021
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1.  
  2. def apply_brightness_contrast(input_img, brightness=0, contrast=0):
  3. if brightness != 0:
  4. if brightness > 0:
  5. shadow = brightness
  6. highlight = 255
  7. else:
  8. shadow = 0
  9. highlight = 255 + brightness
  10. alpha_b = (highlight - shadow) / 255
  11. gamma_b = shadow
  12.  
  13. buf = cv.addWeighted(input_img, alpha_b, input_img, 0, gamma_b)
  14. else:
  15. buf = input_img.copy()
  16.  
  17. if contrast != 0:
  18. f = 131 * (contrast + 127) / (127 * (131 - contrast))
  19. alpha_c = f
  20. gamma_c = 127 * (1 - f)
  21.  
  22. buf = cv.addWeighted(buf, alpha_c, buf, 0, gamma_c)
  23.  
  24. return buf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement