tf.image.adjust_gamma
Stay organized with collections
Save and categorize content based on your preferences.
Performs Gamma Correction.
tf.image.adjust_gamma(
image, gamma=1, gain=1
)
on the input image.
Also known as Power Law Transform. This function converts the
input images at first to float representation, then transforms them
pixelwise according to the equation Out = gain * In**gamma
,
and then converts the back to the original data type.
Usage Example:
x = [[[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]],
[[7.0, 8.0, 9.0],
[10.0, 11.0, 12.0]]]
tf.image.adjust_gamma(x, 0.2)
<tf.Tensor: shape=(2, 2, 3), dtype=float32, numpy=
array([[[1. , 1.1486983, 1.2457309],
[1.319508 , 1.3797297, 1.4309691]],
[[1.4757731, 1.5157166, 1.5518456],
[1.5848932, 1.6153942, 1.6437519]]], dtype=float32)>
Args |
image
|
RGB image or images to adjust.
|
gamma
|
A scalar or tensor. Non-negative real number.
|
gain
|
A scalar or tensor. The constant multiplier.
|
Returns |
A Tensor. A Gamma-adjusted tensor of the same shape and type as image .
|
Raises |
ValueError
|
If gamma is negative.
|
Notes |
For gamma greater than 1, the histogram will shift towards left and
the output image will be darker than the input image.
For gamma less than 1, the histogram will shift towards right and
the output image will be brighter than the input 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.adjust_gamma\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#L2312-L2375) |\n\nPerforms [Gamma Correction](http://en.wikipedia.org/wiki/Gamma_correction).\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.adjust_gamma`](https://www.tensorflow.org/api_docs/python/tf/image/adjust_gamma)\n\n\u003cbr /\u003e\n\n tf.image.adjust_gamma(\n image, gamma=1, gain=1\n )\n\non the input image.\n\nAlso known as Power Law Transform. This function converts the\ninput images at first to float representation, then transforms them\npixelwise according to the equation `Out = gain * In**gamma`,\nand then converts the back to the original data type.\n\n#### Usage Example:\n\n x = [[[1.0, 2.0, 3.0],\n [4.0, 5.0, 6.0]],\n [[7.0, 8.0, 9.0],\n [10.0, 11.0, 12.0]]]\n tf.image.adjust_gamma(x, 0.2)\n \u003ctf.Tensor: shape=(2, 2, 3), dtype=float32, numpy=\n array([[[1. , 1.1486983, 1.2457309],\n [1.319508 , 1.3797297, 1.4309691]],\n [[1.4757731, 1.5157166, 1.5518456],\n [1.5848932, 1.6153942, 1.6437519]]], dtype=float32)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------|-----------------------------------------------|\n| `image` | RGB image or images to adjust. |\n| `gamma` | A scalar or tensor. Non-negative real number. |\n| `gain` | A scalar or tensor. The constant multiplier. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A Tensor. A Gamma-adjusted tensor of the same shape and type as `image`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-----------------------|\n| `ValueError` | If gamma is negative. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Notes ----- ||\n|---|---|\n| For gamma greater than 1, the histogram will shift towards left and the output image will be darker than the input image. For gamma less than 1, the histogram will shift towards right and the output image will be brighter than the input image. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| References ---------- ||\n|---|---|\n| [Wikipedia](http://en.wikipedia.org/wiki/Gamma_correction) ||\n\n\u003cbr /\u003e"]]