
'''simple docstring'''

import numpy as np
from PIL import Image



def        SCREAMING_SNAKE_CASE_  (	snake_case_				:	np.array							)       ->	np.array:
 SCREAMING_SNAKE_CASE				, SCREAMING_SNAKE_CASE				, SCREAMING_SNAKE_CASE  :  Tuple								=		rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
 return 0.2989 * r + 0.5870 * g + 0.1140 * b



def        SCREAMING_SNAKE_CASE_  (	snake_case_				:	np.array							)       ->	np.array:
 return (gray > 127) & (gray <= 255)



def        SCREAMING_SNAKE_CASE_  (	snake_case_				:	np.array   ,     snake_case_				:	np.array							)       ->	np.array:
 SCREAMING_SNAKE_CASE  :  int								=		np.zeros_like(snake_case_							)
 SCREAMING_SNAKE_CASE  :  List[str]								=		np.zeros(
     (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1)							)

 # Copy image to padded image
 SCREAMING_SNAKE_CASE  :  Any								=		image

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


# kernel to be applied
__UpperCAmelCase												=   np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])

if __name__ == "__main__":
   # read original image
   __UpperCAmelCase												=   np.array(Image.open(r'..\image_data\lena.jpg'))
   # Apply erosion operation to a binary image
   __UpperCAmelCase												=   erosion(grayabinary(rgbagray(image)), structuring_element)
   # Save the output image
   __UpperCAmelCase												=   Image.fromarray(output).convert('RGB')
   pil_img.save('result_erosion.png')




'''simple docstring'''

def        SCREAMING_SNAKE_CASE_  (	snake_case_				:	int							)       ->	int:
 if number != int(snake_case_							):
  raise ValueError('factorial() only accepts integral values'							)
 if number < 0:
  raise ValueError('factorial() not defined for negative values'							)
 SCREAMING_SNAKE_CASE  :  str								=		1
 for i in range(1   ,     number + 1							):
  value *= i
 return value



def        SCREAMING_SNAKE_CASE_  (	snake_case_				:	int							)       ->	int:
 if not isinstance(snake_case_   ,     snake_case_							):
  raise ValueError('factorial() only accepts integral values'							)
 if n < 0:
  raise ValueError('factorial() not defined for negative values'							)
 return 1 if n == 0 or n == 1 else n * factorial(n - 1							)


if __name__ == "__main__":
   import doctest

   doctest.testmod()

   __UpperCAmelCase												=   int(input('Enter a positive integer: ').strip() or 0)
   print(f"""factorial{n} is {factorial(n)}""")


