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

Function mean_threshold

computer_vision/mean_threshold.py:9–25  ·  view source on GitHub ↗

image: is a grayscale PIL image object

(image: Image)

Source from the content-addressed store, hash-verified

7
8
9def mean_threshold(image: Image) -> Image:
10 """
11 image: is a grayscale PIL image object
12 """
13 height, width = image.size
14 mean = 0
15 pixels = image.load()
16 for i in range(width):
17 for j in range(height):
18 pixel = pixels[j, i]
19 mean += pixel
20 mean //= width * height
21
22 for j in range(width):
23 for i in range(height):
24 pixels[i, j] = 255 if pixels[i, j] > mean else 0
25 return image
26
27
28if __name__ == "__main__":

Callers 1

mean_threshold.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected