Applies elastic deformation to the image(s).
tf.keras.ops.image.elastic_transform(
images,
alpha=20.0,
sigma=5.0,
interpolation='bilinear',
fill_mode='reflect',
fill_value=0.0,
seed=None,
data_format=None
)
Args |
images
|
Input image or batch of images. Must be 3D or 4D.
|
alpha
|
Scaling factor that controls the intensity of the deformation.
|
sigma
|
Standard deviation of the Gaussian filter used for
smoothing the displacement fields.
|
interpolation
|
Interpolation method. Available methods are "nearest",
and "bilinear". Defaults to "bilinear".
|
fill_mode
|
Points outside the boundaries of the input are filled
according to the given mode. Available methods are "constant",
"nearest", "wrap" and "reflect". Defaults to "constant".
"reflect": (d c b a | a b c d | d c b a)
The input is extended by reflecting about the edge of the last
pixel.
"constant": (k k k k | a b c d | k k k k)
The input is extended by filling all values beyond
the edge with the same constant value k specified by
fill_value.
"wrap": (a b c d | a b c d | a b c d)
The input is extended by wrapping around to the opposite edge.
"nearest": (a a a a | a b c d | d d d d)
The input is extended by the nearest pixel.
|
fill_value
|
Value used for points outside the boundaries of the input if
fill_mode="constant". Defaults to 0.
|
data_format
|
A string specifying the data format of the input tensor.
It can be either "channels_last" or "channels_first".
"channels_last" corresponds to inputs with shape
(batch, height, width, channels), while "channels_first"
corresponds to inputs with shape (batch, channels, height, width).
If not specified, the value will default to
keras.config.image_data_format.
|
Returns |
|
Transformed image or batch of images with elastic deformation.
|
Examples:
x = np.random.random((2, 64, 80, 3)) # batch of 2 RGB images
y = keras.ops.image.elastic_transform(x)
y.shape
(2, 64, 80, 3)
x = np.random.random((64, 80, 3)) # single RGB image
y = keras.ops.image.elastic_transform(x)
y.shape
(64, 80, 3)
x = np.random.random((2, 3, 64, 80)) # batch of 2 RGB images
y = keras.ops.image.elastic_transform(
x, data_format="channels_first")
y.shape
(2, 3, 64, 80)