MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / change_brightness

Function change_brightness

digital_image_processing/change_brightness.py:4–18  ·  view source on GitHub ↗

Change the brightness of a PIL Image to a given level.

(img: Image, level: float)

Source from the content-addressed store, hash-verified

2
3
4def change_brightness(img: Image, level: float) -> Image:
5 """
6 Change the brightness of a PIL Image to a given level.
7 """
8
9 def brightness(c: int) -> float:
10 """
11 Fundamental Transformation/Operation that'll be performed on
12 every bit.
13 """
14 return 128 + level + (c - 128)
15
16 if not -255.0 <= level <= 255.0:
17 raise ValueError("level must be between -255.0 (black) and 255.0 (white)")
18 return img.point(brightness)
19
20
21if __name__ == "__main__":

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected