


"""simple docstring"""
from pathlib import Path

import numpy as np
from PIL import Image






def 		lowercase							(     _snake_case						:      np.ndarray     )     ->np.ndarray:
	"""simple docstring"""





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






def 		lowercase							(     _snake_case						:      np.ndarray     )     ->np.ndarray:
	"""simple docstring"""





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






def 		lowercase							(     _snake_case						:      np.ndarray     ,   _snake_case						:      np.ndarray     )     ->np.ndarray:
	"""simple docstring"""





	__snake_case	:						Union[str, Any]						=				np.zeros_like(_snake_case     )
	__snake_case	:						List[Any]						=				np.zeros(
	    (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1)     )

	# Copy image to padded image
	__snake_case	:						Tuple						=				image

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


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









"""simple docstring"""
def 		lowercase							(     _snake_case						:      int     ,   _snake_case						:      int     )     ->str:
	"""simple docstring"""





	if a < 0 or b < 0:
		raise ValueError('''the value of both inputs must be positive'''     )
	__snake_case	:						Tuple						=				str(bin(_snake_case     )     )[2:]  # remove the leading "0b"
	__snake_case	:						List[Any]						=				str(bin(_snake_case     )     )[2:]
	__snake_case	:						Any						=				max(len(_snake_case     )     ,   len(_snake_case     )     )
	return "0b" + "".join(
	    str(int('''1''' in (char_a, char_b)     )     )
	    for char_a, char_b in zip(a_binary.zfill(_snake_case     )     ,   b_binary.zfill(_snake_case     )     )     )


if __name__ == "__main__":
			import doctest

			doctest.testmod()





