tfg.image.transformer.perspective_transform
Stay organized with collections
Save and categorize content based on your preferences.
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: tfg.image.transformer.ResamplingType
= tfg.image.transformer.ResamplingType.BILINEAR
,
border_type: tfg.image.transformer.BorderType
= tfg.image.transformer.BorderType.ZERO
,
pixel_type: tfg.image.transformer.PixelType
= 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
.
Note |
The transformation matrix maps target to source by transforming output
points to input points.
|
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 and ResamplingType.BILINEAR .
|
border_type
|
Border mode. Supported values are BorderType.ZERO and
BorderType.DUPLICATE .
|
pixel_type
|
Pixel mode. Supported values are PixelType.INTEGER and
PixelType.HALF_INTEGER .
|
name
|
A name for this op. Defaults to "perspective_transform".
|
Returns |
A tensor of shape [B, H_o, W_o, C] containing transformed images.
|
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.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-10-28 UTC.
[null,null,["Last updated 2022-10-28 UTC."],[],[],null,["# tfg.image.transformer.perspective_transform\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/graphics/blob/master/tensorflow_graphics/image/transformer.py#L111-L198) |\n\nApplies a projective transformation to an image. \n\n tfg.image.transformer.perspective_transform(\n image: type_alias.TensorLike,\n transform_matrix: type_alias.TensorLike,\n output_shape: Optional[type_alias.TensorLike] = None,\n resampling_type: ../../../tfg/image/transformer/ResamplingType = ../../../tfg/image/transformer/ResamplingType#BILINEAR,\n border_type: ../../../tfg/image/transformer/BorderType = ../../../tfg/image/transformer/BorderType#ZERO,\n pixel_type: ../../../tfg/image/transformer/PixelType = ../../../tfg/image/transformer/PixelType#HALF_INTEGER,\n name: Optional[str] = 'perspective_transform'\n ) -\u003e tf.Tensor\n\nThe projective transformation is represented by a 3 x 3 matrix\n\\[\\[a0, a1, a2\\], \\[b0, b1, b2\\], \\[c0, c1, c2\\]\\], mapping a point `[x, y]` to a\ntransformed point\n`[x', y'] = [(a0 x + a1 y + a2) / k, (b0 x + b1 y + b2) / k]`, where\n`k = c0 x + c1 y + c2`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Note ---- ||\n|---|---|\n| The transformation matrix maps target to source by transforming output points to input points. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `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. |\n| `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. |\n| `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. |\n| `resampling_type` | Resampling mode. Supported values are [`ResamplingType.NEAREST`](../../../tfg/image/transformer/ResamplingType#NEAREST) and [`ResamplingType.BILINEAR`](../../../tfg/image/transformer/ResamplingType#BILINEAR). |\n| `border_type` | Border mode. Supported values are [`BorderType.ZERO`](../../../tfg/image/transformer/BorderType#ZERO) and [`BorderType.DUPLICATE`](../../../tfg/image/transformer/BorderType#DUPLICATE). |\n| `pixel_type` | Pixel mode. Supported values are [`PixelType.INTEGER`](../../../tfg/image/transformer/PixelType#INTEGER) and [`PixelType.HALF_INTEGER`](../../../tfg/image/transformer/PixelType#HALF_INTEGER). |\n| `name` | A name for this op. Defaults to \"perspective_transform\". |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A tensor of shape `[B, H_o, W_o, C]` containing transformed images. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | If `image` has rank != 4. If `transform_matrix` has rank \\\u003c 3 or its last two dimensions are not 3. If `image` and `transform_matrix` batch dimension does not match. |\n\n\u003cbr /\u003e"]]