

'''simple docstring'''
from pathlib import Path

import numpy as np
from PIL import Image







def  _A		(     snake_case					)      ->     np.ndarray:
   _lowercase					,				_lowercase					,				_lowercase      :				List[str]      					=       rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
   return 0.2989 * r + 0.5870 * g + 0.1140 * b







def  _A		(     snake_case					)      ->     np.ndarray:
   return (gray > 1_27) & (gray <= 2_55)







def  _A		(     snake_case		,							snake_case					)      ->     np.ndarray:
   _lowercase      :				Dict      					=       np.zeros_like(snake_case					)
   _lowercase      :				Union[str, Any]      					=       np.zeros(
       (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1)					)

   # Copy image to padded image
   _lowercase      :				str      					=       image

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


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









'''simple docstring'''
from __future__ import annotations







def  _A		(     snake_case		,							snake_case = None		,							snake_case = None					)      ->     None:
   if start is None:
      _lowercase      :				Dict      					=       0

   if end is None:
      _lowercase      :				List[Any]      					=       len(snake_case					) - 1

   if start >= end:
      return

   _lowercase      :				int      					=       (start + end) // 2

   slowsort(snake_case		,							snake_case		,							snake_case					)
   slowsort(snake_case		,							mid + 1		,							snake_case					)

   if sequence[end] < sequence[mid]:
      _lowercase					,				_lowercase      :				Any      					=       sequence[mid], sequence[end]

   slowsort(snake_case		,							snake_case		,							end - 1					)


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

    testmod()






