Warning: This project is deprecated. TensorFlow Addons has stopped development,
The project will only be providing minimal maintenance releases until May 2024. See the full
announcement here or on
github.
tfa.image.sparse_image_warp
Stay organized with collections
Save and categorize content based on your preferences.
Image warping using correspondences between sparse control points.
tfa.image.sparse_image_warp(
image: tfa.types.TensorLike
,
source_control_point_locations: tfa.types.TensorLike
,
dest_control_point_locations: tfa.types.TensorLike
,
interpolation_order: int = 2,
regularization_weight: tfa.types.FloatTensorLike
= 0.0,
num_boundary_points: int = 0,
name: str = 'sparse_image_warp'
) -> tf.Tensor
Apply a non-linear warp to the image, where the warp is specified by
the source and destination locations of a (potentially small) number of
control points. First, we use a polyharmonic spline
(tfa.image.interpolate_spline
) to interpolate the displacements
between the corresponding control points to a dense flow field.
Then, we warp the image using this dense flow field
(tfa.image.dense_image_warp
).
Let t index our control points. For regularization_weight = 0
, we have:
warped_image[b, dest_control_point_locations[b, t, 0],
dest_control_point_locations[b, t, 1], :] =
image[b, source_control_point_locations[b, t, 0],
source_control_point_locations[b, t, 1], :].
For regularization_weight > 0
, this condition is met approximately, since
regularized interpolation trades off smoothness of the interpolant vs.
reconstruction of the interpolant at the control points.
See tfa.image.interpolate_spline
for further documentation of the
interpolation_order
and regularization_weight
arguments.
Args |
image
|
Either a 2-D float Tensor of shape [height, width] ,
a 3-D Tensor of shape [height, width, channels] ,
or a 4-D Tensor of shape [batch_size, height, width, channels] .
batch_size is assumed as one when image is a 2-D or 3-D Tensor .
|
source_control_point_locations
|
[batch_size, num_control_points, 2] float
Tensor .
|
dest_control_point_locations
|
[batch_size, num_control_points, 2] float
Tensor .
|
interpolation_order
|
polynomial order used by the spline interpolation
|
regularization_weight
|
weight on smoothness regularizer in interpolation
|
num_boundary_points
|
How many zero-flow boundary points to include at
each image edge. Usage:
num_boundary_points=0 : don't add zero-flow points
num_boundary_points=1 : 4 corners of the image
num_boundary_points=2 : 4 corners and one in the middle of each edge
(8 points total)
num_boundary_points=n : 4 corners and n-1 along each edge
|
name
|
A name for the operation (optional).
Note that image and offsets can be of type tf.half , tf.float32 , or
tf.float64 , and do not necessarily have to be the same type.
|
Returns |
warped_image
|
a float Tensor with the same shape and dtype as image .
|
flow_field
|
[batch_size, height, width, 2] float Tensor containing the
dense flow field produced by the interpolation.
|
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 2023-05-25 UTC.
[null,null,["Last updated 2023-05-25 UTC."],[],[],null,["# tfa.image.sparse_image_warp\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/addons/blob/v0.20.0/tensorflow_addons/image/sparse_image_warp.py#L116-L237) |\n\nImage warping using correspondences between sparse control points. \n\n tfa.image.sparse_image_warp(\n image: ../../tfa/types/TensorLike,\n source_control_point_locations: ../../tfa/types/TensorLike,\n dest_control_point_locations: ../../tfa/types/TensorLike,\n interpolation_order: int = 2,\n regularization_weight: ../../tfa/types/FloatTensorLike = 0.0,\n num_boundary_points: int = 0,\n name: str = 'sparse_image_warp'\n ) -\u003e tf.Tensor\n\nApply a non-linear warp to the image, where the warp is specified by\nthe source and destination locations of a (potentially small) number of\ncontrol points. First, we use a polyharmonic spline\n([`tfa.image.interpolate_spline`](../../tfa/image/interpolate_spline)) to interpolate the displacements\nbetween the corresponding control points to a dense flow field.\nThen, we warp the image using this dense flow field\n([`tfa.image.dense_image_warp`](../../tfa/image/dense_image_warp)).\n\nLet t index our control points. For `regularization_weight = 0`, we have:\nwarped_image\\[b, dest_control_point_locations\\[b, t, 0\\],\ndest_control_point_locations\\[b, t, 1\\], :\\] =\nimage\\[b, source_control_point_locations\\[b, t, 0\\],\nsource_control_point_locations\\[b, t, 1\\], :\\].\n\nFor `regularization_weight \u003e 0`, this condition is met approximately, since\nregularized interpolation trades off smoothness of the interpolant vs.\nreconstruction of the interpolant at the control points.\nSee [`tfa.image.interpolate_spline`](../../tfa/image/interpolate_spline) for further documentation of the\n`interpolation_order` and `regularization_weight` arguments.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `image` | Either a 2-D float `Tensor` of shape `[height, width]`, a 3-D `Tensor` of shape `[height, width, channels]`, or a 4-D `Tensor` of shape `[batch_size, height, width, channels]`. `batch_size` is assumed as one when `image` is a 2-D or 3-D `Tensor`. |\n| `source_control_point_locations` | `[batch_size, num_control_points, 2]` float `Tensor`. |\n| `dest_control_point_locations` | `[batch_size, num_control_points, 2]` float `Tensor`. |\n| `interpolation_order` | polynomial order used by the spline interpolation |\n| `regularization_weight` | weight on smoothness regularizer in interpolation |\n| `num_boundary_points` | How many zero-flow boundary points to include at each image edge. Usage: \u003cbr /\u003e - `num_boundary_points=0`: don't add zero-flow points - `num_boundary_points=1`: 4 corners of the image - `num_boundary_points=2`: 4 corners and one in the middle of each edge (8 points total) - `num_boundary_points=n`: 4 corners and n-1 along each edge |\n| `name` | A name for the operation (optional). Note that `image` and `offsets` can be of type [`tf.half`](https://www.tensorflow.org/api_docs/python/tf#half), [`tf.float32`](https://www.tensorflow.org/api_docs/python/tf#float32), or [`tf.float64`](https://www.tensorflow.org/api_docs/python/tf#float64), and do not necessarily have to be the same type. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|----------------|----------------------------------------------------------------------------------------------------------------|\n| `warped_image` | a float `Tensor` with the same shape and dtype as `image`. |\n| `flow_field` | `[batch_size, height, width, 2]` float `Tensor` containing the dense flow field produced by the interpolation. |\n\n\u003cbr /\u003e"]]