'''simple docstring'''

from __future__ import annotations



def lowerCamelCase__						(       A_       ,			A_       ,			A_       ):
	assert n > 1 and a > 0 and greatest_common_divisor(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       ) == 1
	(UpperCAmelCase_)				       =					extended_gcd(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       )  # Implemented below
	UpperCAmelCase_				       =					(b * s) % n
	return x



def lowerCamelCase__						(       A_       ,			A_       ):
	(UpperCAmelCase_)				       =					extended_euclid(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       )  # Implemented below
	if b < 0:
		UpperCAmelCase_				       =					(b % n + n) % n
	return b



def lowerCamelCase__						(       A_       ,			A_       ,			A_       ):
	UpperCAmelCase_				       =					invert_modulo(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE       )
	UpperCAmelCase_				       =					(b * s) % n
	return x



def lowerCamelCase__						(       A_       ,			A_       ):
	assert a >= 0 and b >= 0

	if b == 0:
		UpperCAmelCase_				       =					a, 1, 0
	else:
		(UpperCAmelCase_)				       =					extended_gcd(_SCREAMING_SNAKE_CASE       ,			a % b       )
		UpperCAmelCase_				       =					q
		UpperCAmelCase_				       =					p - q * (a // b)

	assert a % d == 0 and b % d == 0
	assert d == a * x + b * y

	return (d, x, y)



def lowerCamelCase__						(       A_       ,			A_       ):
	if b == 0:
		return (1, 0)
	(UpperCAmelCase_)				       =					extended_euclid(_SCREAMING_SNAKE_CASE       ,			a % b       )
	UpperCAmelCase_				       =					a // b
	return (y, x - k * y)



def lowerCamelCase__						(       A_       ,			A_       ):
	if a < b:
		UpperCAmelCase_				       =					b, a

	while a % b != 0:
		UpperCAmelCase_				       =					b, a % b

	return b


if __name__ == "__main__":
						from doctest import testmod

						testmod(name='''modular_division''', verbose=True)
						testmod(name='''modular_division2''', verbose=True)
						testmod(name='''invert_modulo''', verbose=True)
						testmod(name='''extended_gcd''', verbose=True)
						testmod(name='''extended_euclid''', verbose=True)
						testmod(name='''greatest_common_divisor''', verbose=True)

'''simple docstring'''

import numpy as np
from PIL import Image



def lowerCamelCase__						(       A_       ):
 UpperCAmelCase_       ,       UpperCAmelCase_       ,       UpperCAmelCase_				       =					rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
 return 0.2989 * r + 0.5870 * g + 0.1140 * b



def lowerCamelCase__						(       A_       ):
 return (gray > 127) & (gray <= 255)



def lowerCamelCase__						(       A_       ,			A_       ):
 UpperCAmelCase_				       =					np.zeros_like(A_       )
 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 == 5       )
 return output


# kernel to be applied
__snake_case       :   List[str]  		=    np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])

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