o
    oi                     @   sn   d Z ddlmZ ddlmZ ddlmZ dededefdd	Zd
ededefddZdededefddZ	dS )z.Module containing the affine distortion model.    N)Tensor)KORNIA_CHECK_SHAPE#projected_points_in_camera_z1_planeparamsreturnc           
      C   sz   t | ddg t |ddg | d }| d }|d |d }}|d |d }}|| | }|| | }	tj||	gdd	S )
aU  Distort one or more points from the canonical z=1 plane into the camera frame.

    .. math::
        \begin{bmatrix} u \\ v \end{bmatrix} =
        \begin{bmatrix} f_x & 0 \\ 0 & f_y \end{bmatrix}
        \begin{bmatrix} x \\ y \end{bmatrix} +
        \begin{bmatrix} c_x \\ c_y \end{bmatrix}

    Args:
        projected_points_in_camera_z1_plane: Tensor representing the points to distort with shape (..., 2).
        params: Tensor representing the parameters of the affine distortion model with shape (..., 4).

    Returns:
        Tensor representing the distorted points with shape (..., 2).

    Example:
        >>> points = torch.tensor([319.5, 239.5])  # center of a 640x480 image
        >>> params = torch.tensor([600., 600., 319.5, 239.5])
        >>> distort_points_affine(points, params)
        tensor([192019.5000, 143939.5000])

    *24.r   .   .   .   dimr   opsstack)
r   r   xyfxfycxcyuv r   \/home/ubuntu/.local/lib/python3.10/site-packages/kornia/geometry/camera/distortion_affine.pydistort_points_affine      r!   distorted_points_in_camerac           
      C   sz   t | ddg t |ddg | d }| d }|d |d }}|d |d }}|| | }|| | }	tj||	gdd	S )
aG  Undistort one or more points from the camera frame into the canonical z=1 plane.

    .. math::
        \begin{bmatrix} x \\ y \end{bmatrix} =
        \begin{bmatrix} u \\ v \end{bmatrix} -
        \begin{bmatrix} c_x \\ c_y \end{bmatrix}
        \begin{bmatrix} f_x & 0 \\ 0 & f_y \end{bmatrix}^{-1}

    Args:
        distorted_points_in_camera: Tensor representing the points to undistort with shape (..., 2).
        params: Tensor representing the parameters of the affine distortion model with shape (..., 4).

    Returns:
        Tensor representing the undistorted points with shape (..., 2).

    Example:
        >>> points = torch.tensor([319.5, 239.5])  # center of a 640x480 image
        >>> params = torch.tensor([600., 600., 319.5, 239.5])
        >>> undistort_points_affine(points, params)
        tensor([0., 0.])

    r   r   r	   r
   r   r   r   r   r   r   )
r#   r   r   r   r   r   r   r   r   r   r   r   r    undistort_points_affine@   r"   r$   c                 C   sf   t | ddg t |ddg |d |d }}t|}tjtj||gddtj||gddgddS )	a0  Compute the derivative of the x distortion with respect to the x coordinate.

    .. math::
        \frac{\partial u}{\partial x} =
        \begin{bmatrix} f_x & 0 \\ 0 & f_y \end{bmatrix}

    Args:
        projected_points_in_camera_z1_plane: Tensor representing the points to distort with shape (..., 2).
        params: Tensor representing the parameters of the affine distortion model with shape (..., 4).

    Returns:
        Tensor representing the derivative of the x distortion with respect to the x coordinate with shape (..., 2).

    Example:
        >>> points = torch.tensor([319.5, 239.5])  # center of a 640x480 image
        >>> params = torch.tensor([600., 600., 319.5, 239.5])
        >>> dx_distort_points_affine(points, params)
        tensor([[600.,   0.],
                [  0., 600.]])

    r   r   r	   r
   r   r   r   )r   r   
zeros_liker   )r   r   r   r   zerosr   r   r    dx_distort_points_affinef   s
   
.r(   )
__doc__kornia.corecorer   r   kornia.core.checkr   r!   r$   r(   r   r   r   r    <module>   s   &&