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

from .haversine_distance import haversine_distance

__lowerCAmelCase					   =       637_8137.0
__lowerCAmelCase					   =       635_6752.31_4245
__lowerCAmelCase					   =       6_3_7_8_1_3_7


def    a      ( a		,						a		,						a		,						a	)     ->float:




			'''simple docstring'''


			SCREAMING_SNAKE_CASE     						= (AXIS_A - AXIS_B) / AXIS_A
			# Parametric latitudes
			# https://en.wikipedia.org/wiki/Latitude#Parametric_(or_reduced)_latitude
			SCREAMING_SNAKE_CASE     						= atan((1 - flattening) * tan(radians(a	)	)	)
			SCREAMING_SNAKE_CASE     						= atan((1 - flattening) * tan(radians(a	)	)	)

			# Compute central angle between two points
			# using haversine theta. sigma =  haversine_distance / equatorial radius
			SCREAMING_SNAKE_CASE     						= haversine_distance(a		,						a		,						a		,						a	) / EQUATORIAL_RADIUS

			# Intermediate P and Q values
			SCREAMING_SNAKE_CASE     						= (b_lata + b_lata) / 2
			SCREAMING_SNAKE_CASE     						= (b_lata - b_lata) / 2

			# Intermediate X value
			# X = (sigma - sin(sigma)) * sin^2Pcos^2Q / cos^2(sigma/2)
			SCREAMING_SNAKE_CASE     						= (sin(a	) ** 2) * (cos(a	) ** 2)
			SCREAMING_SNAKE_CASE     						= cos(sigma / 2	) ** 2
			SCREAMING_SNAKE_CASE     						= (sigma - sin(a	)) * (x_numerator / x_demonimator)

			# Intermediate Y value
			# Y = (sigma + sin(sigma)) * cos^2Psin^2Q / sin^2(sigma/2)
			SCREAMING_SNAKE_CASE     						= (cos(a	) ** 2) * (sin(a	) ** 2)
			SCREAMING_SNAKE_CASE     						= sin(sigma / 2	) ** 2
			SCREAMING_SNAKE_CASE     						= (sigma + sin(a	)) * (y_numerator / y_denominator)

			return EQUATORIAL_RADIUS * (sigma - ((flattening / 2) * (x_value + y_value)))


if __name__ == "__main__":
							import doctest

							doctest.testmod()

from PIL import Image


def    a      ( a	)     ->Image:




			'''simple docstring'''


			SCREAMING_SNAKE_CASE						,							SCREAMING_SNAKE_CASE     						= image.size
			SCREAMING_SNAKE_CASE     						= 0
			SCREAMING_SNAKE_CASE     						= image.load()
			for i in range(a	):
						for j in range(a	):
									SCREAMING_SNAKE_CASE     						= pixels[j, i]
									mean += pixel
			mean //= width * height

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


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