



from pathlib import Path

import numpy as np
from PIL import Image






def 			lowerCAmelCase__	(					lowerCamelCase_	:	np.ndarray):





				'''simple docstring'''

				lowerCAmelCase__  :       str				=  rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
				return 0.2989 * r + 0.5870 * g + 0.1140 * b






def 			lowerCAmelCase__	(					lowerCamelCase_	:	np.ndarray):





				'''simple docstring'''

				return (gray > 127) & (gray <= 255)






def 			lowerCAmelCase__	(					lowerCamelCase_	:	np.ndarray ,lowerCamelCase_	:	np.ndarray):





				'''simple docstring'''

				lowerCAmelCase__  :       Union[str, Any]				=  np.zeros_like(lowerCamelCase_)
				lowerCAmelCase__  :       Any				=  np.zeros(
				    (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1))

				# Copy image to padded image
				lowerCAmelCase__  :       List[Any]				=  image

				# Iterate over image & apply kernel
				for x in range(image.shape[1]):
								for y in range(image.shape[0]):
												lowerCAmelCase__  :       Union[str, Any]				=  (
												    kernel * image_padded[y : y + kernel.shape[0], x : x + kernel.shape[1]]
												).sum()
												lowerCAmelCase__  :       Tuple				=  int(summation > 0)
				return output


if __name__ == "__main__":
							# read original image
							__snake_case       :	Union[str, Any]            =Path(__file__).resolve().parent / 'image_data' / 'lena.jpg'
							__snake_case       :	Optional[Any]            =np.array(Image.open(lena_path))
							# kernel to be applied
							__snake_case       :	int            =np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])
							__snake_case       :	Union[str, Any]            =dilation(gray_to_binary(rgb_to_gray(lena)), structuring_element)
							# Save the output image
							__snake_case       :	List[str]            =Image.fromarray(output).convert('RGB')
							pil_img.save('result_dilation.png')






def 			lowerCAmelCase__	(					lowerCamelCase_	:	int):





				'''simple docstring'''

				if length <= 0 or not isinstance(lowerCamelCase_ ,lowerCamelCase_):
								raise ValueError('''Length must be a positive integer.''')
				return [n * (2 * n - 1) for n in range(lowerCamelCase_)]


if __name__ == "__main__":
							print(hexagonal_numbers(length=5))
							print(hexagonal_numbers(length=1_0))

