




from PIL import Image

def  UpperCAmelCase_							(				__UpperCAmelCase						:     Image							) ->			Optional[int]:
						SCREAMING_SNAKE_CASE_     						=      image.size
						SCREAMING_SNAKE_CASE_     						=      0
						SCREAMING_SNAKE_CASE_     						=      image.load()
						for i in range(UpperCamelCase__							):
												for j in range(UpperCamelCase__							):
																		SCREAMING_SNAKE_CASE_     						=      pixels[j, i]
																		mean += pixel
						mean //= width * height

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


if __name__ == "__main__":
			lowerCamelCase__			:       Union[str, Any]         =							mean_threshold(Image.open('path_to_image').convert('L'))
			image.save('output_image_path')





def  UpperCAmelCase_							(				__UpperCAmelCase						:     int      ,      __UpperCAmelCase						:     int							) ->			int:
      return int((input_a, input_a).count(0							) != 0							)

def  UpperCAmelCase_							(				) ->			None:
      assert nand_gate(0      ,      0							) == 1
      assert nand_gate(0      ,      1							) == 1
      assert nand_gate(1      ,      0							) == 1
      assert nand_gate(1      ,      1							) == 0


if __name__ == "__main__":
   print(nand_gate(0, 0))
   print(nand_gate(0, 1))
   print(nand_gate(1, 0))
   print(nand_gate(1, 1))