





from pathlib import Path

import numpy as np
from PIL import Image
def      A__       (    SCREAMING_SNAKE_CASE_   :      np.ndarray						)  ->  np.ndarray:






   """simple docstring"""







   _UpperCAmelCase       ,      _UpperCAmelCase       ,      _UpperCAmelCase           =   rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
   return 0.2_9_8_9 * r + 0.5_8_7_0 * g + 0.1_1_4_0 * b
def      A__       (    SCREAMING_SNAKE_CASE_   :      np.ndarray						)  ->  np.ndarray:






   """simple docstring"""







   return (gray > 1_27) & (gray <= 2_55)
def      A__       (    SCREAMING_SNAKE_CASE_   :      np.ndarray				,	SCREAMING_SNAKE_CASE_   :      np.ndarray						)  ->  np.ndarray:






   """simple docstring"""







   _UpperCAmelCase           =   np.zeros_like(SCREAMING_SNAKE_CASE_						)
   _UpperCAmelCase           =   np.zeros(
       (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1)						)

   # Copy image to padded image
   _UpperCAmelCase           =   image

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


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


def 			lowerCamelCase__			(       _a):
	if not isinstance(_a				,      _a):
		SCREAMING_SNAKE_CASE :   Tuple					  =							f"Input value of [number={number}] must be an integer"
		raise TypeError(_a)
	if number < 0:
		return False
	SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							number * number
	while number > 0:
		if number % 10 != number_square % 10:
			return False
		number //= 10
		number_square //= 10
	return True


if __name__ == "__main__":
			import doctest

			doctest.testmod()