Image.warp_perspective#

Image.warp_perspective(H: Any, method: str = 'linear', inverse: bool = False, tile: bool = False, size: tuple[int, int] | None = None, background: Any = None) Self | tuple[Self, ndarray, ndarray][source]#

Perspective warp

Parameters:
  • H (ndarray(3,3)) – homography

  • method (str, optional) – interpolation mode: ‘linear’ [default], ‘nearest’

  • inverse (bool, optional) – use inverse of H, defaults to False

  • tile (bool, optional) – return minimal enclosing tile, defaults to False

  • size (array_like(2), optional) – size of output image, defaults to size of input image

  • background (scalar, array_like, optional) – value for pixels outside the image, defaults to 0

Raises:

TypeError – H must be a 3x3 NumPy array

Returns:

warped image

Return type:

Image

Applies a perspective warp to the input image.

\[\begin{split}Y_{u,v} = X_{u^\prime, v^\prime} \mbox{, where } u^\prime=\frac{\tilde{u}}{\tilde{w}}, v^\prime=\frac{\tilde{v}}{\tilde{w}}, \begin{pmatrix} \tilde{u} \\ \tilde{v} \\ \tilde{w} \end{pmatrix} = \mat{H} \begin{pmatrix} u \\ v \\ 1 \end{pmatrix}\end{split}\]

The resulting image may be smaller or larger than the input image. If tile is True then the output image is the smallest rectangle that contains the warped result, and its position with respect to the origin of the input image, and the coordinates of the four corners of the input image.

Pixels that are not present in the original image are set to the value specified by background.

References:
Seealso:

warp opencv.warpPerspective