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.
|