



from pathlib import Path

import numpy as np
from PIL import Image

def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			np.ndarray    ):
				"""simple docstring"""







				__a     ,					__a     ,					__a       =		rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
				return 0.2989 * r + 0.5870 * g + 0.1140 * b

def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			np.ndarray    ):
				"""simple docstring"""







				return (gray > 127) & (gray <= 255)

def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			np.ndarray				,     _SCREAMING_SNAKE_CASE       :			np.ndarray    ):
				"""simple docstring"""







				__a       =		np.zeros_like(_SCREAMING_SNAKE_CASE    )
				__a       =		np.zeros(
				    (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1)    )

				# Copy image to padded image
				__a       =		image

				# Iterate over image & apply kernel
				for x in range(image.shape[1]    ):
								for y in range(image.shape[0]    ):
												__a       =		(
												    kernel * image_padded[y : y + kernel.shape[0], x : x + kernel.shape[1]]
												).sum()
												__a       =		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""")





def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			int = 3				,     _SCREAMING_SNAKE_CASE       :			int = 7				,     _SCREAMING_SNAKE_CASE       :			int = 100_0000    ):
				"""simple docstring"""







				__a       =		0
				__a       =		1

				for current_denominator in range(1				,     limit + 1    ):
								__a       =		current_denominator * numerator // denominator
								if current_denominator % denominator == 0:
												current_numerator -= 1
								if current_numerator * max_denominator > current_denominator * max_numerator:
												__a       =		current_numerator
												__a       =		current_denominator
				return max_numerator


if __name__ == "__main__":
						print(solution(numerator=3, denominator=7, limit=100_0000))
