# tfg.image.transformer.perspective_transform

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/graphics/blob/master/tensorflow_graphics/image/transformer.py#L111-L198) |

Applies a projective transformation to an image.

    tfg.image.transformer.perspective_transform(
        image: type_alias.TensorLike,
        transform_matrix: type_alias.TensorLike,
        output_shape: Optional[type_alias.TensorLike] = None,
        resampling_type: https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/ResamplingType = https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/ResamplingType#BILINEAR,
        border_type: https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/BorderType = https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/BorderType#ZERO,
        pixel_type: https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/PixelType = https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/PixelType#HALF_INTEGER,
        name: Optional[str] = 'perspective_transform'
    ) -> tf.Tensor

The projective transformation is represented by a 3 x 3 matrix
\[\[a0, a1, a2\], \[b0, b1, b2\], \[c0, c1, c2\]\], mapping a point `[x, y]` to a
transformed point
`[x', y'] = [(a0 x + a1 y + a2) / k, (b0 x + b1 y + b2) / k]`, where
`k = c0 x + c1 y + c2`.

<br />

<br />

<br />

| ## Note ||
|---|---|
| The transformation matrix maps target to source by transforming output points to input points. ||

<br />

<br />

<br />

<br />

| ## Args ||
|---|---|
| `image` | A tensor of shape `[B, H_i, W_i, C]`, where `B` is the batch size, `H_i` the height of the image, `W_i` the width of the image, and `C` the number of channels of the image. |
| `transform_matrix` | A tensor of shape `[B, 3, 3]` containing projective transform matrices. The transformation maps target to source by transforming output points to input points. |
| `output_shape` | The heigh `H_o` and width `W_o` output dimensions after the transform. If None, output is the same size as input image. |
| `resampling_type` | Resampling mode. Supported values are [`ResamplingType.NEAREST`](https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/ResamplingType#NEAREST) and [`ResamplingType.BILINEAR`](https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/ResamplingType#BILINEAR). |
| `border_type` | Border mode. Supported values are [`BorderType.ZERO`](https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/BorderType#ZERO) and [`BorderType.DUPLICATE`](https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/BorderType#DUPLICATE). |
| `pixel_type` | Pixel mode. Supported values are [`PixelType.INTEGER`](https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/PixelType#INTEGER) and [`PixelType.HALF_INTEGER`](https://www.tensorflow.org/graphics/api_docs/python/tfg/image/transformer/PixelType#HALF_INTEGER). |
| `name` | A name for this op. Defaults to "perspective_transform". |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tensor of shape `[B, H_o, W_o, C]` containing transformed images. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If `image` has rank != 4. If `transform_matrix` has rank \< 3 or its last two dimensions are not 3. If `image` and `transform_matrix` batch dimension does not match. |

<br />