





from math import asin, atan, cos, radians, sin, sqrt, tan

__lowerCamelCase :  Optional[int]										=  6_3_7_8_1_3_7.0
__lowerCamelCase :  Tuple										=  6_3_5_6_7_5_2.3_1_4_2_4_5
__lowerCamelCase :  Tuple										=  637_8137



def 	A_       (  _lowerCAmelCase							,     _lowerCAmelCase							,     _lowerCAmelCase							,     _lowerCAmelCase  )		->				float:
 UpperCamelCase			:      List[Any] 			=     (AXIS_A - AXIS_B) / AXIS_A
 UpperCamelCase			:      Optional[int] 			=     atan((1 - flattening) * tan(radians(_lowerCAmelCase  )  )  )
 UpperCamelCase			:      Tuple 			=     atan((1 - flattening) * tan(radians(_lowerCAmelCase  )  )  )
 UpperCamelCase			:      Tuple 			=     radians(_lowerCAmelCase  )
 UpperCamelCase			:      Any 			=     radians(_lowerCAmelCase  )
 # Equation
 UpperCamelCase			:      Dict 			=     sin((phi_a - phi_a) / 2  )
 UpperCamelCase			:      Tuple 			=     sin((lambda_a - lambda_a) / 2  )
 # Square both values
 sin_sq_phi *= sin_sq_phi
 sin_sq_lambda *= sin_sq_lambda
 UpperCamelCase			:      int 			=     sqrt(sin_sq_phi + (cos(_lowerCAmelCase  ) * cos(_lowerCAmelCase  ) * sin_sq_lambda)  )
 return 2 * RADIUS * asin(_lowerCAmelCase  )


if __name__ == "__main__":
    import doctest

    doctest.testmod()







from PIL import Image



def 	A_       (  _lowerCAmelCase  )		->				Image:
 UpperCamelCase			,					UpperCamelCase			:      List[Any] 			=     image.size
 UpperCamelCase			:      Union[str, Any] 			=     0
 UpperCamelCase			:      List[str] 			=     image.load()
 for i in range(_lowerCAmelCase  ):
  for j in range(_lowerCAmelCase  ):
   UpperCamelCase			:      List[Any] 			=     pixels[j, i]
   mean += pixel
 mean //= width * height

 for j in range(_lowerCAmelCase  ):
  for i in range(_lowerCAmelCase  ):
   UpperCamelCase			:      Union[str, Any] 			=     255 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""")
