
'''simple docstring'''







import numpy as np
from cva import COLOR_BGR2GRAY, CV_8UC3, cvtColor, filteraD, imread, imshow, waitKey
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			Optional[Any]				,				__SCREAMING_SNAKE_CASE :			List[Any]				,				__SCREAMING_SNAKE_CASE :			int				,				__SCREAMING_SNAKE_CASE :			Dict				,				__SCREAMING_SNAKE_CASE :			Optional[int]				,				__SCREAMING_SNAKE_CASE :			Any							):



						"""simple docstring"""





						if (ksize % 2) == 0:
												lowercase_     :					List[Any]													=	ksize + 1
						lowercase_     :					Tuple													=	np.zeros((ksize, ksize)				,				dtype=np.floataa							)

						# each value
						for y in range(SCREAMING_SNAKE_CASE_							):
												for x in range(SCREAMING_SNAKE_CASE_							):
																		# distance from center
																		lowercase_     :					Union[str, Any]													=	x - ksize // 2
																		lowercase_     :					Optional[int]													=	y - ksize // 2

																		# degree to radiant
																		lowercase_     :					str													=	theta / 180 * np.pi
																		lowercase_     :					Union[str, Any]													=	np.cos(_theta							)
																		lowercase_     :					str													=	np.sin(_theta							)

																		# get kernel x
																		lowercase_     :					List[str]													=	cos_theta * px + sin_theta * py

																		# get kernel y
																		lowercase_     :					Union[str, Any]													=	-sin_theta * px + cos_theta * py

																		# fill kernel
																		lowercase_     :					Optional[int]													=	np.exp(
																		    -(_x**2 + gamma**2 * _y**2) / (2 * sigma**2)							) * np.cos(2 * np.pi * _x / lambd + psi							)

						return gabor


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						# read original image
						_lowercase			:  Dict   							=	imread("../image_data/lena.jpg")
						# turn image in gray scale value
						_lowercase			:  Tuple   							=	cvtColor(img, COLOR_BGR2GRAY)

						# Apply multiple Kernel to detect edges
						_lowercase			:  Dict   							=	np.zeros(gray.shape[:2])
						for theta in [0, 3_0, 6_0, 9_0, 1_2_0, 1_5_0]:
												_lowercase			:  str   							=	gabor_filter_kernel(1_0, 8, theta, 1_0, 0, 0)
												out += filteraD(gray, CV_8UC3, kernel_aa)
						_lowercase			:  List[Any]   							=	out / out.max() * 2_5_5
						_lowercase			:  Any   							=	out.astype(np.uinta)

						imshow("Original", gray)
						imshow("Gabor filter with 20x20 mask and 6 directions", out)

						waitKey(0)





'''simple docstring'''







from PIL import Image
def  snake_case_		(    __SCREAMING_SNAKE_CASE :			Image				,				__SCREAMING_SNAKE_CASE :			int							):



						"""simple docstring"""





						lowercase_     :					Optional[int]													=	(259 * (level + 255)) / (255 * (259 - level))

						def contrast(__SCREAMING_SNAKE_CASE :			int							) -> int:
												return int(128 + factor * (c - 128)							)

						return img.point(__SCREAMING_SNAKE_CASE							)


if __name__ == "__main__":
							# Load image
							with Image.open("image_data/lena.jpg") as img:
														# Change contrast to 170
														_lowercase			:  Union[str, Any]   							=	change_contrast(img, 1_7_0)
														cont_img.save("image_data/lena_high_contrast.png", format="png")



