





from __future__ import annotations

from numpy import array, cos, cross, floataa, radians, sin
from numpy.typing import NDArray



def 		A_    (					_lowerCAmelCase							,       _lowerCAmelCase							,       _lowerCAmelCase = False					)						->			list[float]:
 if radian_mode:
  return [magnitude * cos(_lowerCAmelCase					), magnitude * sin(_lowerCAmelCase					)]
 return [magnitude * cos(radians(_lowerCAmelCase					)					), magnitude * sin(radians(_lowerCAmelCase					)					)]



def 		A_    (					_lowerCAmelCase							,       _lowerCAmelCase							,       _lowerCAmelCase = 10**-1					)						->			bool:
 UpperCamelCase     : NDArray[floataa]	     =       cross(_lowerCAmelCase							,       _lowerCAmelCase					)
 UpperCamelCase     : float	     =       sum(_lowerCAmelCase					)
 return abs(_lowerCAmelCase					) < eps


if __name__ == "__main__":
    # Test to check if it works
    __lowerCamelCase	:					int			  =					array(
        [
            polar_force(7_1_8.4, 180 - 30),
            polar_force(8_7_9.5_4, 45),
            polar_force(100, -90),
        ]
    )

    __lowerCamelCase	:					NDArray[floataa]			  =					array([[0, 0], [0, 0], [0, 0]])

    assert in_static_equilibrium(forces, location)

    # Problem 1 in image_data/2D_problems.jpg
    __lowerCamelCase	:					int			  =					array(
        [
            polar_force(30 * 9.8_1, 15),
            polar_force(215, 180 - 45),
            polar_force(264, 90 - 30),
        ]
    )

    __lowerCamelCase	:					Optional[Any]			  =					array([[0, 0], [0, 0], [0, 0]])

    assert in_static_equilibrium(forces, location)

    # Problem in image_data/2D_problems_1.jpg
    __lowerCamelCase	:					str			  =					array([[0, -2000], [0, -1200], [0, 1_5600], [0, -1_2400]])

    __lowerCamelCase	:					Dict			  =					array([[0, 0], [6, 0], [10, 0], [12, 0]])

    assert in_static_equilibrium(forces, location)

    import doctest

    doctest.testmod()







from pathlib import Path

import numpy as np
from PIL import Image



def 		A_    (					_lowerCAmelCase					)						->			np.ndarray:
 UpperCamelCase     ,   UpperCamelCase     ,   UpperCamelCase     : Optional[Any]	     =       rgb[:, :, 0], rgb[:, :, 1], rgb[:, :, 2]
 return 0.2_989 * r + 0.5_870 * g + 0.1_140 * b



def 		A_    (					_lowerCAmelCase					)						->			np.ndarray:
 return (gray > 127) & (gray <= 255)



def 		A_    (					_lowerCAmelCase							,       _lowerCAmelCase					)						->			np.ndarray:
 UpperCamelCase     : Dict	     =       np.zeros_like(_lowerCAmelCase					)
 UpperCamelCase     : List[str]	     =       np.zeros(
     (image.shape[0] + kernel.shape[0] - 1, image.shape[1] + kernel.shape[1] - 1)					)

 # Copy image to padded image
 UpperCamelCase     : Tuple	     =       image

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


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