




import numpy as np
from PIL import Image







def       _a (		SCREAMING_SNAKE_CASE_				:							np.array	):
					__lowerCAmelCase  ,				__lowerCAmelCase  ,				__lowerCAmelCase							  =			rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
					return 0.29_89 * r + 0.58_70 * g + 0.11_40 * b







def       _a (		SCREAMING_SNAKE_CASE_				:							np.array	):
					return (gray > 1_27) & (gray <= 2_55)







def       _a (		SCREAMING_SNAKE_CASE_				:							np.array , SCREAMING_SNAKE_CASE_				:							np.array	):
					__lowerCAmelCase							  =			np.zeros_like(SCREAMING_SNAKE_CASE_	)
					__lowerCAmelCase							  =			np.zeros(
					    (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1)	)

					# Copy image to padded image
					__lowerCAmelCase							  =			image

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


# kernel to be applied
UpperCamelCase__            =     np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])

if __name__ == "__main__":
					# read original image
					UpperCamelCase__            =     np.array(Image.open(R"""..\image_data\lena.jpg"""))
					# Apply erosion operation to a binary image
					UpperCamelCase__            =     erosion(grayabinary(rgbagray(image)), structuring_element)
					# Save the output image
					UpperCamelCase__            =     Image.fromarray(output).convert("""RGB""")
					pil_img.save("""result_erosion.png""")










from __future__ import annotations

from pathlib import Path







def       _a (		SCREAMING_SNAKE_CASE_				:							tuple[int, int] , SCREAMING_SNAKE_CASE_				:							tuple[int, int]	):
					return pointa[0] * pointa[1] - pointa[1] * pointa[0]







def       _a (		SCREAMING_SNAKE_CASE_				:							int , SCREAMING_SNAKE_CASE_				:							int , SCREAMING_SNAKE_CASE_				:							int , SCREAMING_SNAKE_CASE_				:							int , SCREAMING_SNAKE_CASE_				:							int , SCREAMING_SNAKE_CASE_				:							int	):
					__lowerCAmelCase							  =			(xa, ya)
					__lowerCAmelCase							  =			(xa - xa, ya - ya)
					__lowerCAmelCase							  =			(xa - xa, ya - ya)
					__lowerCAmelCase							  =			-vector_product(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_	) / vector_product(
					    SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_	)
					__lowerCAmelCase							  =			+vector_product(SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_	) / vector_product(
					    SCREAMING_SNAKE_CASE_ , SCREAMING_SNAKE_CASE_	)

					return a > 0 and b > 0 and a + b < 1







def       _a (		SCREAMING_SNAKE_CASE_				:							str = "p102_triangles.txt"	):
					__lowerCAmelCase							  =			Path(SCREAMING_SNAKE_CASE_	).parent.joinpath(SCREAMING_SNAKE_CASE_	).read_text(encoding="utf-8"	)

					__lowerCAmelCase							  =			[]
					for line in data.strip().split("\n"	):
										triangles.append([int(SCREAMING_SNAKE_CASE_	) for number in line.split(","	)]	)

					__lowerCAmelCase							  =			0
					__lowerCAmelCase							  =			42

					for triangle in triangles:
										ret += contains_origin(*SCREAMING_SNAKE_CASE_	)

					return ret


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




