tf.image.central_crop
Stay organized with collections
Save and categorize content based on your preferences.
Crop the central region of the image(s).
tf.image.central_crop(
image, central_fraction
)
Remove the outer parts of an image but retain the central region of the image
along each dimension. If we specify central_fraction = 0.5, this function
returns the region marked with "X" in the below diagram.
--------
| |
| XXXX |
| XXXX |
| | where "X" is the central 50% of the image.
--------
This function works on either a single image (image
is a 3-D Tensor), or a
batch of images (image
is a 4-D Tensor).
Args |
image
|
Either a 3-D float Tensor of shape [height, width, depth], or a 4-D
Tensor of shape [batch_size, height, width, depth].
|
central_fraction
|
float (0, 1], fraction of size to crop
|
Usage Example: python >> import tensorflow as tf >> x =
tf.random.normal(shape=(256, 256, 3)) >> tf.image.central_crop(x, 0.5)
Raises |
ValueError
|
if central_crop_fraction is not within (0, 1].
|
Returns |
3-D / 4-D float Tensor, as per the input.
|
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 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.image.central_crop\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 2 version](/api_docs/python/tf/image/central_crop) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/image_ops_impl.py#L617-L723) |\n\nCrop the central region of the image(s).\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.image.central_crop`](/api_docs/python/tf/image/central_crop), \\`tf.compat.v2.image.central_crop\\`\n\n\u003cbr /\u003e\n\n tf.image.central_crop(\n image, central_fraction\n )\n\nRemove the outer parts of an image but retain the central region of the image\nalong each dimension. If we specify central_fraction = 0.5, this function\nreturns the region marked with \"X\" in the below diagram. \n\n --------\n | |\n | XXXX |\n | XXXX |\n | | where \"X\" is the central 50% of the image.\n --------\n\nThis function works on either a single image (`image` is a 3-D Tensor), or a\nbatch of images (`image` is a 4-D Tensor).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------------|-----------------------------------------------------------------------------------------------------------------------------|\n| `image` | Either a 3-D float Tensor of shape \\[height, width, depth\\], or a 4-D Tensor of shape \\[batch_size, height, width, depth\\]. |\n| `central_fraction` | float (0, 1\\], fraction of size to crop |\n\n\u003cbr /\u003e\n\nUsage Example: `python \u003e\u003e import tensorflow as tf \u003e\u003e x =\ntf.random.normal(shape=(256, 256, 3)) \u003e\u003e tf.image.central_crop(x, 0.5)`\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-------------------------------------------------|\n| `ValueError` | if central_crop_fraction is not within (0, 1\\]. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| 3-D / 4-D float Tensor, as per the input. ||\n\n\u003cbr /\u003e"]]