tf.keras.ops.image.crop_images
Stay organized with collections
Save and categorize content based on your preferences.
Crop images
to a specified height
and width
.
tf.keras.ops.image.crop_images(
images,
top_cropping=None,
left_cropping=None,
target_height=None,
target_width=None,
bottom_cropping=None,
right_cropping=None
)
Args |
images
|
4-D batch of images of shape (batch, height, width, channels)
or 3-D single image of shape (height, width, channels) .
|
top_cropping
|
Number of columns to crop from the top.
|
bottom_cropping
|
Number of columns to crop from the bottom.
|
left_cropping
|
Number of columns to crop from the left.
|
right_cropping
|
Number of columns to crop from the right.
|
target_height
|
Height of the output images.
|
target_width
|
Width of the 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.reshape(np.arange(1, 28, dtype="float32"), [3, 3, 3])
images[:,:,0] # print the first channel of the images
array([[ 1., 4., 7.],
[10., 13., 16.],
[19., 22., 25.]], dtype=float32)
cropped_images = keras.image.crop_images(images, 0, 0, 2, 2)
cropped_images[:,:,0] # print the first channel of the cropped images
array([[ 1., 4.],
[10., 13.]], dtype=float32)
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.crop_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#L947-L1005) |\n\nCrop `images` to a specified `height` and `width`. \n\n tf.keras.ops.image.crop_images(\n images,\n top_cropping=None,\n left_cropping=None,\n target_height=None,\n target_width=None,\n bottom_cropping=None,\n right_cropping=None\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|---------------------------------------------------------------------------------------------------------------------------|\n| `images` | 4-D batch of images of shape `(batch, height, width, channels)` or 3-D single image of shape `(height, width, channels)`. |\n| `top_cropping` | Number of columns to crop from the top. |\n| `bottom_cropping` | Number of columns to crop from the bottom. |\n| `left_cropping` | Number of columns to crop from the left. |\n| `right_cropping` | Number of columns to crop from the right. |\n| `target_height` | Height of the output images. |\n| `target_width` | Width of the 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.reshape(np.arange(1, 28, dtype=\"float32\"), [3, 3, 3])\n images[:,:,0] # print the first channel of the images\n array([[ 1., 4., 7.],\n [10., 13., 16.],\n [19., 22., 25.]], dtype=float32)\n cropped_images = keras.image.crop_images(images, 0, 0, 2, 2)\n cropped_images[:,:,0] # print the first channel of the cropped images\n array([[ 1., 4.],\n [10., 13.]], dtype=float32)"]]