




"""simple docstring"""




from cva import COLOR_BGR2GRAY, cvtColor, imread, imshow, waitKey
from numpy import array, dot, pad, ravel, uinta, zeros







def       __UpperCAmelCase      (				__UpperCamelCase					,							__UpperCamelCase					):
			__lowercase	,__lowercase	:       str				=   image.shape
			__lowercase	:       Any				=   cols - block_size[1] + 1
			__lowercase	:       Union[str, Any]				=   rows - block_size[0] + 1
			__lowercase	:       List[str]				=   zeros((dst_height * dst_width, block_size[1] * block_size[0])					)
			__lowercase	:       Dict				=   0
			for i in range(0					,							__UpperCamelCase					):
						for j in range(0					,							__UpperCamelCase					):
									__lowercase	:       Optional[Any]				=   ravel(image[i : i + block_size[0], j : j + block_size[1]]					)
									__lowercase	:       str				=   window
									row += 1

			return image_array







def       __UpperCAmelCase      (				__UpperCamelCase					,							__UpperCamelCase					):
			__lowercase	,__lowercase	:       List[str]				=   image.shape[0], image.shape[1]
			__lowercase	:       str				=   filter_kernel.shape[0]
			__lowercase	:       Tuple				=   k_size // 2
			# Pads image with the edge values of array.
			__lowercase	:       Optional[Any]				=   pad(__UpperCamelCase					,							__UpperCamelCase					,							mode='''edge'''					)

			# im2col, turn the k_size*k_size pixels into a row and np.vstack all rows
			__lowercase	:       int				=   imacol(__UpperCamelCase					,							(k_size, k_size)					)

			#  turn the kernel into shape(k*k, 1)
			__lowercase	:       Optional[int]				=   ravel(__UpperCamelCase					)
			# reshape and get the dst image
			__lowercase	:       str				=   dot(__UpperCamelCase					,							__UpperCamelCase					).reshape(__UpperCamelCase					,							__UpperCamelCase					)
			return dst


if __name__ == "__main__":
			# read original image
			a_            =   imread(r'../image_data/lena.jpg')
			# turn image in gray scale value
			a_            =   cvtColor(img, COLOR_BGR2GRAY)
			# Laplace operator
			a_            =   array([[0, 1, 0], [1, -4, 1], [0, 1, 0]])
			a_            =   img_convolve(gray, Laplace_kernel).astype(uinta)
			imshow('Laplacian', out)
			waitKey(0)









"""simple docstring"""




a_            =   1_0_0_0







def       __UpperCAmelCase      (				__UpperCamelCase					):
			return x * x







def       __UpperCAmelCase      (				__UpperCamelCase					,							__UpperCamelCase					,							__UpperCamelCase					,							__UpperCamelCase = 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

			__lowercase	:       Optional[Any]				=   (b - a) / N_STEPS
			__lowercase	:       Optional[int]				=   function(__UpperCamelCase					) + function(__UpperCamelCase					)

			for i in range(1					,							__UpperCamelCase					):
						__lowercase	:       Union[str, 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()



