Skip to content

Commit e9622d6

Browse files
committed
Add doctests to change_brightness
Added comprehensive doctests for change_brightness function. Contributes to #9943
1 parent a71618f commit e9622d6

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

digital_image_processing/change_brightness.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@
44
def change_brightness(img: Image, level: float) -> Image:
55
"""
66
Change the brightness of a PIL Image to a given level.
7+
8+
Args:
9+
img: PIL Image to adjust
10+
level: Brightness level adjustment (-255.0 to 255.0)
11+
Negative values darken, positive values brighten
12+
13+
Returns:
14+
New PIL Image with adjusted brightness
15+
16+
Raises:
17+
ValueError: If level is not in range [-255.0, 255.0]
18+
19+
>>> from PIL import Image
20+
>>> import numpy as np
21+
>>> img = Image.new('RGB', (2, 2), color=(100, 100, 100))
22+
>>> bright = change_brightness(img, 50)
23+
>>> px = bright.load()
24+
>>> px[0, 0]
25+
(150, 150, 150)
26+
>>> dark = change_brightness(img, -50)
27+
>>> px_dark = dark.load()
28+
>>> px_dark[0, 0]
29+
(50, 50, 50)
30+
>>> change_brightness(img, 300)
31+
Traceback (most recent call last):
32+
...
33+
ValueError: level must be between -255.0 (black) and 255.0 (white)
734
"""
835

936
def brightness(c: int) -> float:

0 commit comments

Comments
 (0)