tf.image.total_variation
Stay organized with collections
Save and categorize content based on your preferences.
Calculate and return the total variation for one or more images.
tf.image.total_variation(
images, name=None
)
Used in the notebooks
The total variation is the sum of the absolute differences for neighboring
pixel-values in the input images. This measures how much noise is in the
images.
This can be used as a loss-function during optimization so as to suppress
noise in images. If you have a batch of images, then you should calculate
the scalar loss-value as the sum:
loss = tf.reduce_sum(tf.image.total_variation(images))
This implements the anisotropic 2-D version of the formula described here:
https://en.wikipedia.org/wiki/Total_variation_denoising
Args |
images
|
4-D Tensor of shape [batch, height, width, channels] or 3-D Tensor
of shape [height, width, channels] .
|
name
|
A name for the operation (optional).
|
Raises |
ValueError
|
if images.shape is not a 3-D or 4-D vector.
|
Returns |
The total variation of images .
If images was 4-D, return a 1-D float Tensor of shape [batch] with the
total variation for each image in the batch.
If images was 3-D, return a scalar float with the total variation for
that image.
|
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-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.image.total_variation\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/image_ops_impl.py#L3337-L3406) |\n\nCalculate and return the total variation for one or more images.\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.total_variation`](https://www.tensorflow.org/api_docs/python/tf/image/total_variation)\n\n\u003cbr /\u003e\n\n tf.image.total_variation(\n images, name=None\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|-------------------------------------------------------------------------------------------|\n| - [Neural style transfer](https://www.tensorflow.org/tutorials/generative/style_transfer) |\n\nThe total variation is the sum of the absolute differences for neighboring\npixel-values in the input images. This measures how much noise is in the\nimages.\n\nThis can be used as a loss-function during optimization so as to suppress\nnoise in images. If you have a batch of images, then you should calculate\nthe scalar loss-value as the sum:\n`loss = tf.reduce_sum(tf.image.total_variation(images))`\n\nThis implements the anisotropic 2-D version of the formula described here:\n\n\u003chttps://en.wikipedia.org/wiki/Total_variation_denoising\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------|------------------------------------------------------------------------------------------------------------|\n| `images` | 4-D Tensor of shape `[batch, height, width, channels]` or 3-D Tensor of shape `[height, width, channels]`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|---------------------------------------------|\n| `ValueError` | if images.shape is not a 3-D or 4-D vector. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The total variation of `images`. \u003cbr /\u003e If `images` was 4-D, return a 1-D float Tensor of shape `[batch]` with the total variation for each image in the batch. If `images` was 3-D, return a scalar float with the total variation for that image. ||\n\n\u003cbr /\u003e"]]