



from cva import COLOR_BGR2GRAY, cvtColor, imread, imshow, waitKey
from numpy import divide, inta, multiply, ravel, sort, zeros_like


def       UpperCamelCase(  __UpperCamelCase							:		Tuple					,__UpperCamelCase							:		Union[str, Any]=3			):
		lowerCAmelCase_      :					str     =			int(mask / 2			)
		# copy image size
		lowerCAmelCase_      :					Dict     =			zeros_like(__UpperCamelCase			)
		for i in range(__UpperCamelCase					,gray_img.shape[0] - bd			):
				for j in range(__UpperCamelCase					,gray_img.shape[1] - bd			):
						# get mask according with mask
						lowerCAmelCase_      :					Optional[Any]     =			ravel(gray_img[i - bd : i + bd + 1, j - bd : j + bd + 1]			)
						# calculate mask median
						lowerCAmelCase_      :					int     =			sort(__UpperCamelCase			)[inta(divide((multiply(__UpperCamelCase					,__UpperCamelCase			))					,2			) + 1			)]
						lowerCAmelCase_      :					Dict     =			median
		return median_img


if __name__ == "__main__":
						# read original image
						A__  :  Dict       = imread('''../image_data/lena.jpg''')
						# turn image in gray scale value
						A__  :  Dict       = cvtColor(img, COLOR_BGR2GRAY)

						# get values with two different mask size
						A__  :  Any       = median_filter(gray, 3)
						A__  :  Optional[Any]       = median_filter(gray, 5)

						# show result images
						imshow('''median filter with 3x3 mask''', medianaxa)
						imshow('''median filter with 5x5 mask''', medianaxa)
						waitKey(0)










A__  :  str       = 1000


def       UpperCamelCase(  __UpperCamelCase							:		float			):
		return x * x


def       UpperCamelCase(  __UpperCamelCase							:		Optional[int]					,__UpperCamelCase							:		float					,__UpperCamelCase							:		float					,__UpperCamelCase							:		int = 4			):
		assert callable(
		    __UpperCamelCase			), f"""the function(object) passed should be callable your input : {function}"""
		assert isinstance(__UpperCamelCase					,(float, int)			), f"""a should be float or integer your input : {a}"""
		assert isinstance(function(__UpperCamelCase			)					,(float, int)			), (
		    "the function should return integer or float return type of your function, "
		    f"""{type(__UpperCamelCase			)}"""
		)
		assert isinstance(__UpperCamelCase					,(float, int)			), f"""b should be float or integer your input : {b}"""
		assert (
		    isinstance(__UpperCamelCase					,__UpperCamelCase			) and precision > 0
		), f"""precision should be positive integer your input : {precision}"""

		# just applying the formula of simpson for approximate integration written in
		# mentioned article in first comment of this file and above this function

		lowerCAmelCase_      :					List[str]     =			(b - a) / N_STEPS
		lowerCAmelCase_      :					str     =			function(__UpperCamelCase			) + function(__UpperCamelCase			)

		for i in range(1					,__UpperCamelCase			):
				lowerCAmelCase_      :					Optional[Any]     =			a + h * i
				result += function(__UpperCamelCase			) * (4 if i % 2 else 2)

		result *= h / 3
		return round(__UpperCamelCase					,__UpperCamelCase			)


if __name__ == "__main__":
						import doctest

						doctest.testmod()





