Equalization
classkeras.layers.Equalization(value_range=(0, 255), bins=256, data_format=None, **kwargs)
Preprocessing layer for histogram equalization on image channels.
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.
Note: This layer is safe to use inside a tf.data
pipeline
(independently of which backend you're using).
Arguments
[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.Input shape
3D (unbatched) or 4D (batched) tensor with shape:
(..., height, width, channels)
, in "channels_last"
format,
or (..., channels, height, width)
, in "channels_first"
format.
Output shape
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)