tf.keras.layers.Equalization

Preprocessing layer for histogram equalization on image channels.

Inherits From: Layer, Operation

Histogram equalization is a technique to adjust image intensities to enhance contrast by effectively spreading out the most frequent intensity values. This layer applies equalization on a channel-wise basis, which can improve the visibility of details in images.

This layer works with both grayscale and color images, performing equalization independently on each color channel. At inference time, the equalization is consistently applied.

value_range Optional list/tuple of 2 floats specifying the lower and upper limits of the input data values. Defaults to [0, 255]. If the input image has been scaled, use the appropriate range (e.g., [0.0, 1.0]). The equalization will be scaled to this range, and output values will be clipped accordingly.
bins Integer specifying the number of histogram bins to use for equalization. Defaults to 256, which is suitable for 8-bit images. Larger values can provide more granular intensity redistribution.

3D unbatched) or 4D (batched) tensor with shape

(..., height, width, channels), in "channels_last" format, or (..., channels, height, width), in "channels_first" format.

3D unbatched) or 4D (batched) tensor with shape

(..., target_height, target_width, channels), or (..., channels, target_height, target_width), in "channels_first" format.

Example:

# Create an equalization layer for standard 8-bit images
equalizer = keras.layers.Equalization()

# An image with uneven intensity distribution
image = [...] # your input image

# Apply histogram equalization
equalized_image = equalizer(image)

# For images with custom value range
custom_equalizer = keras.layers.Equalization(
    value_range=[0.0, 1.0],  # for normalized images
    bins=128  # fewer bins for more subtle equalization
)
custom_equalized = custom_equalizer(normalized_image)

input Retrieves the input tensor(s) of a symbolic operation.

Only returns the tensor(s) corresponding to the first time the operation was called.

output Retrieves the output tensor(s) of a layer.

Only returns the tensor(s) corresponding to the first time the operation was called.

Methods

convert_weight

View source

Convert the weight if it is from the a different backend.

from_config

View source

Creates an operation from its config.

This method is the reverse of get_config, capable of instantiating the same operation from the config dictionary.

if "dtype" in config and isinstance(config["dtype"], dict):
    policy = dtype_policies.deserialize(config["dtype"])

Args
config A Python dictionary, typically the output of get_config.

Returns
An operation instance.

get_random_transformation

View source

transform_bounding_boxes

View source

transform_images

View source

transform_labels

View source

transform_segmentation_masks

View source

transform_single_bounding_box

View source

transform_single_image

View source

transform_single_label

View source

transform_single_segmentation_mask

View source