




from PIL import Image





def        __UpperCAmelCase						(							lowerCamelCase_ :     Image  )       ->  Image:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_  ,    SCREAMING_SNAKE_CASE_   : List[Any]					  =      image.size
			SCREAMING_SNAKE_CASE_   : str					  =      0
			SCREAMING_SNAKE_CASE_   : Dict					  =      image.load()
			for i in range(lowerCamelCase_  ):
						for j in range(lowerCamelCase_  ):
									SCREAMING_SNAKE_CASE_   : List[Any]					  =      pixels[j, i]
									mean += pixel
			mean //= width * height

			for j in range(lowerCamelCase_  ):
						for i in range(lowerCamelCase_  ):
									SCREAMING_SNAKE_CASE_   : List[Any]					  =      2_55 if pixels[i, j] > mean else 0
			return image


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











"""simple docstring"""
def 				lowercase__		(					lowerCamelCase,						lowerCamelCase       ):
				return numa ^ numa < 0


if __name__ == "__main__":
			import doctest

			doctest.testmod()

