
from pathlib import Path

import numpy as np
from PIL import Image


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__		):
      UpperCamelCase__				,UpperCamelCase__				,UpperCamelCase__    :   Dict					=				rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
      return 0.2989 * r + 0.5870 * g + 0.1140 * b


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__		):
      return (gray > 1_2_7) & (gray <= 2_5_5)


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__ ,		UpperCamelCase__		):
      UpperCamelCase__    :   int					=				np.zeros_like(UpperCamelCase__		)
      UpperCamelCase__    :   Union[str, Any]					=				np.zeros(
          (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1)		)

      # Copy image to padded image
      UpperCamelCase__    :   Dict					=				image

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


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




import math


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__		):
      UpperCamelCase__    :   List[str]					=				math.loga(math.sqrt(4 * positive_integer + 1		) / 2 + 1 / 2		)

      return exponent == int(UpperCamelCase__		)


def 							SCREAMING_SNAKE_CASE_      (			UpperCamelCase__ = 1 / 1_2_3_4_5		):
      UpperCamelCase__    :   Dict					=				0
      UpperCamelCase__    :   Tuple					=				0

      UpperCamelCase__    :   Optional[Any]					=				3
      while True:
            UpperCamelCase__    :   Union[str, Any]					=				(integer**2 - 1) / 4
            # if candidate is an integer, then there is a partition for k
            if partition_candidate == int(UpperCamelCase__		):
                  UpperCamelCase__    :   int					=				int(UpperCamelCase__		)
                  total_partitions += 1
                  if check_partition_perfect(UpperCamelCase__		):
                        perfect_partitions += 1
            if perfect_partitions > 0:
                  if perfect_partitions / total_partitions < max_proportion:
                        return int(UpperCamelCase__		)
            integer += 1


if __name__ == "__main__":
    print(F'''{solution() = }''')


