View source on GitHub
|
Apply a scale and translation to the images.
tf.keras.ops.image.scale_and_translate(
images,
output_shape,
scale,
translation,
spatial_dims,
method,
antialias=True
)
Generates a new image of output_shape by resampling from the input image
using the sampling method corresponding to method. For 2D images, this
operation transforms a location in the input images, (x, y), to a location
in the output image according to:
(x * scale[1] + translation[1], y * scale[0] + translation[0]).
(Note the inverse warp is used to generate the sample locations.) Assumes half-centered pixels, i.e the pixel at integer location row, col has coordinates y, x = row + 0.5, col + 0.5, and similarly for other input image dimensions.
If an output location(pixel) maps to an input sample location that is outside the input boundaries then the value for the output location will be set to zero.
The method argument expects one of the following resize methods:
"linear","bilinear","trilinear","triangle": Linear interpolation. Ifantialiasis True, uses a triangular filter when downsampling."cubic","bicubic","tricubic": Cubic interpolation, using the Keys cubic kernel."lanczos3": Lanczos resampling, using a kernel of radius 3."lanczos5": Lanczos resampling, using a kernel of radius 5.
Returns | |
|---|---|
| The scale and translated images. |
Example:
images = np.arange(9, dtype="float32").reshape((3, 3))scale = np.array([2.0, 2.0]).astype("float32")translation = -(scale / 2.0 - 0.5)resized_images = keras.image.scale_and_translate(images, (5, 5), scale, translation, (0, 1), "linear")resized_imagesarray([[0.0 0.5 1.0 1.5 2.0][1.5 2.0 2.5 3.0 3.5][3.0 3.5 4.0 4.5 5.0][4.5 5.0 5.5 6.0 6.5][6.0 6.5 7.0 7.5 8.0]], dtype=float32)
View source on GitHub