Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Changing Brightness
Brightness adjustment makes an image lighter or darker. It is useful for normalising images taken in different lighting conditions.
8 min•By Priygop Team•Updated 2026
Brightness Adjustment
Brightness Adjustment
import cv2
import numpy as np
image = cv2.imread("photo.jpg")
def adjust_brightness(image, value):
"""
Adjust brightness by adding/subtracting a value.
value > 0: brighter
value < 0: darker
"""
# cv2.add handles saturation automatically (no wrap-around)
if value >= 0:
added = cv2.add(image, np.full(image.shape, value, dtype=np.uint8))
else:
subtracted = cv2.subtract(image, np.full(image.shape, -value, dtype=np.uint8))
return subtracted
return added
brighter = adjust_brightness(image, 60)
darker = adjust_brightness(image, -60)
# Alternative: using convertScaleAbs(alpha, beta)
# alpha = contrast multiplier (1.0 = no change)
# beta = brightness addend (0 = no change)
brighter2 = cv2.convertScaleAbs(image, alpha=1.0, beta=60)
darker2 = cv2.convertScaleAbs(image, alpha=1.0, beta=-60)
cv2.imwrite("brighter.jpg", brighter)
cv2.imwrite("darker.jpg", darker)
print("Brightness adjustments complete")Diagram
Loading diagram…
Machine Learning follows a structured pipeline from data to deployment