





'''simple docstring'''
def     lowercase__       (       __lowercase						:  int    ,  __lowercase						:  int = 1000					)			->				str:



       """simple docstring"""






       if (not isinstance(__lowercase    ,  __lowercase					)) or (digit_position <= 0):
              raise ValueError('Digit position must be a positive integer'					)
       elif (not isinstance(__lowercase    ,  __lowercase					)) or (precision < 0):
              raise ValueError('Precision must be a nonnegative integer'					)

       # compute an approximation of (16 ** (n - 1)) * pi whose fractional part is mostly
       # accurate
       __UpperCamelCase	=  (
           4 * _subsum(__lowercase    ,  1    ,  __lowercase					)
           - 2 * _subsum(__lowercase    ,  4    ,  __lowercase					)
           - _subsum(__lowercase    ,  5    ,  __lowercase					)
           - _subsum(__lowercase    ,  6    ,  __lowercase					)
       )

       # return the first hex digit of the fractional part of the result
       return hex(int((sum_result % 1) * 16					)					)[2:]
def     lowercase__       (       __lowercase						:  int    ,  __lowercase						:  int    ,  __lowercase						:  int					)			->				float:



       """simple docstring"""






       __UpperCamelCase	=  0.0
       for sum_index in range(digit_pos_to_extract + precision					):
              __UpperCamelCase	=  8 * sum_index + denominator_addend
              if sum_index < digit_pos_to_extract:
                     # if the exponential term is an integer and we mod it by the denominator
                     # before dividing, only the integer part of the sum will change;
                     # the fractional part will not
                     __UpperCamelCase	=  pow(
                         16    ,  digit_pos_to_extract - 1 - sum_index    ,  __lowercase					)
              else:
                     __UpperCamelCase	=  pow(16    ,  digit_pos_to_extract - 1 - sum_index					)
              total += exponential_term / denominator
       return total


if __name__ == "__main__":
    import doctest

    doctest.testmod()







'''simple docstring'''
import numpy as np
from PIL import Image
def     lowercase__       (       __lowercase						:  np.array					)			->				np.array:



       """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     lowercase__       (       __lowercase						:  np.array					)			->				np.array:



       """simple docstring"""






       return (gray > 127) & (gray <= 255)
def     lowercase__       (       __lowercase						:  np.array    ,  __lowercase						:  np.array					)			->				np.array:



       """simple docstring"""






       __UpperCamelCase	=  np.zeros_like(__lowercase					)
       __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
a__							:							Dict			=np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])

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