Skip to content

Commit 328f7f6

Browse files
committed
Add doctests to mean_threshold
Contributes to #9943
1 parent a71618f commit 328f7f6

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

computer_vision/mean_threshold.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,27 @@
88

99
def mean_threshold(image: Image) -> Image:
1010
"""
11-
image: is a grayscale PIL image object
11+
Apply mean thresholding to a grayscale image.
12+
13+
Converts image to binary: pixels above mean become white (255),
14+
pixels below mean become black (0).
15+
16+
Args:
17+
image: Grayscale PIL Image object
18+
19+
Returns:
20+
Thresholded PIL Image (binary)
21+
22+
>>> from PIL import Image
23+
>>> import numpy as np
24+
>>> arr = np.array([[50, 100], [150, 200]], dtype=np.uint8)
25+
>>> img = Image.fromarray(arr, mode='L')
26+
>>> result = mean_threshold(img.copy())
27+
>>> px = result.load()
28+
>>> px[0, 0]
29+
0
30+
>>> px[1, 1]
31+
255
1232
"""
1333
height, width = image.size
1434
mean = 0

0 commit comments

Comments
 (0)