



from PIL import Image


def A						(       __UpperCamelCase					)						->      Image:
			A__     , A__       =    image.size
			A__       =    0
			A__       =    image.load()
			for i in range(__UpperCamelCase					):
						for j in range(__UpperCamelCase					):
									A__       =    pixels[j, i]
									mean += pixel
			mean //= width * height

			for j in range(__UpperCamelCase					):
						for i in range(__UpperCamelCase					):
									A__       =    255 if pixels[i, j] > mean else 0
			return image


if __name__ == "__main__":
							SCREAMING_SNAKE_CASE__       =      mean_threshold(Image.open('''path_to_image''').convert('''L'''))
							image.save('''output_image_path''')









def A						(       __UpperCamelCase					)						->      bool:
			return number & 1 == 0


if __name__ == "__main__":
							import doctest

							doctest.testmod()




