tf.keras.ops.image.pad_images
Stay organized with collections
Save and categorize content based on your preferences.
Pad images
with zeros to the specified height
and width
.
tf.keras.ops.image.pad_images(
images,
top_padding=None,
left_padding=None,
target_height=None,
target_width=None,
bottom_padding=None,
right_padding=None
)
Args |
images
|
4D Tensor of shape (batch, height, width, channels) or 3D
Tensor of shape (height, width, channels) .
|
top_padding
|
Number of rows of zeros to add on top.
|
bottom_padding
|
Number of rows of zeros to add at the bottom.
|
left_padding
|
Number of columns of zeros to add on the left.
|
right_padding
|
Number of columns of zeros to add on the right.
|
target_height
|
Height of output images.
|
target_width
|
Width of output images.
|
Returns |
If images were 4D, a 4D float Tensor of shape
(batch, target_height, target_width, channels)
If images were 3D, a 3D float Tensor of shape
(target_height, target_width, channels)
|
Example:
images = np.random.random((15, 25, 3))
padded_images = keras.ops.image.pad_images(
images, 2, 3, target_height=20, target_width=30
)
padded_images.shape
(20, 30, 3)
batch_images = np.random.random((2, 15, 25, 3))
padded_batch = keras.ops.image.pad_images(
batch_images, 2, 3, target_height=20, target_width=30
)
padded_batch.shape
(2, 20, 30, 3)
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. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.ops.image.pad_images\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/image.py#L718-L780) |\n\nPad `images` with zeros to the specified `height` and `width`. \n\n tf.keras.ops.image.pad_images(\n images,\n top_padding=None,\n left_padding=None,\n target_height=None,\n target_width=None,\n bottom_padding=None,\n right_padding=None\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------|----------------------------------------------------------------------------------------------------------|\n| `images` | 4D Tensor of shape `(batch, height, width, channels)` or 3D Tensor of shape `(height, width, channels)`. |\n| `top_padding` | Number of rows of zeros to add on top. |\n| `bottom_padding` | Number of rows of zeros to add at the bottom. |\n| `left_padding` | Number of columns of zeros to add on the left. |\n| `right_padding` | Number of columns of zeros to add on the right. |\n| `target_height` | Height of output images. |\n| `target_width` | Width of output images. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| If `images` were 4D, a 4D float Tensor of shape `(batch, target_height, target_width, channels)` If `images` were 3D, a 3D float Tensor of shape `(target_height, target_width, channels)` ||\n\n\u003cbr /\u003e\n\n#### Example:\n\n images = np.random.random((15, 25, 3))\n padded_images = keras.ops.image.pad_images(\n images, 2, 3, target_height=20, target_width=30\n )\n padded_images.shape\n (20, 30, 3)\n\n batch_images = np.random.random((2, 15, 25, 3))\n padded_batch = keras.ops.image.pad_images(\n batch_images, 2, 3, target_height=20, target_width=30\n )\n padded_batch.shape\n (2, 20, 30, 3)"]]