




from pathlib import Path

import numpy as np
from PIL import Image







def      _a				(						SCREAMING_SNAKE_CASE_							:    np.ndarray					):
					__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.ndarray					):
					return (gray > 1_27) & (gray <= 2_55)







def      _a				(						SCREAMING_SNAKE_CASE_							:    np.ndarray				,				SCREAMING_SNAKE_CASE_							:    np.ndarray					):
					__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 > 0					)
					return output


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










from __future__ import annotations







def      _a				(						SCREAMING_SNAKE_CASE_							:    float				,				SCREAMING_SNAKE_CASE_							:    float				,				SCREAMING_SNAKE_CASE_							:    float				,				):
					if (electron_conc, hole_conc, intrinsic_conc).count(0					) != 1:
										raise ValueError("You cannot supply more or less than 2 values"					)
					elif electron_conc < 0:
										raise ValueError("Electron concentration cannot be negative in a semiconductor"					)
					elif hole_conc < 0:
										raise ValueError("Hole concentration cannot be negative in a semiconductor"					)
					elif intrinsic_conc < 0:
										raise ValueError(
										    "Intrinsic concentration cannot be negative in a semiconductor"					)
					elif electron_conc == 0:
										return (
										    "electron_conc",
										    intrinsic_conc**2 / hole_conc,
										)
					elif hole_conc == 0:
										return (
										    "hole_conc",
										    intrinsic_conc**2 / electron_conc,
										)
					elif intrinsic_conc == 0:
										return (
										    "intrinsic_conc",
										    (electron_conc * hole_conc) ** 0.5,
										)
					else:
										return (-1, -1)


if __name__ == "__main__":
					import doctest

					doctest.testmod()




