ImageDev

Clahe2d

Performs a Contrast Limited Adaptive Histogram Equalization (CLAHE) on a two-dimensional image.

Access to parameter description

The Contrast Limited Adaptive Histogram Equalization (CLAHE) algorithm is a widely used method for locally enhancing the contrast of images. It improves the visibility of details in low-contrast images by assigning each pixel an output value based on a transformation function derived from the histogram of a surrounding tile.

Homegenous regions can generate strong peaks in the histogram. Applying equalization to such histograms tends to over-amplify noise. To address this, a contrast limiting mechanism is applied, which truncates the histogram of each tile at a specified clip limit. If a histogram bin exceeds this limit, the corresponding pixel intensities are redistributed uniformly among other bins.
The maximum number of elements $M$ in a histogram bin is given by: $$ M = Cl \times \frac{P}{N} $$ Where: Once the histogram is computed and clipped, a histogram equalization process is performed independently on each tile. This process redistributes the pixel intensities within the tile's histogram range, effectively enhancing the contrast.

By default, the histograms are computed only on contiguous tiles, providing accurate results for each tile center. Other pixel values are computed by interpolating the histograms computed for overlapping tiles. Alternatively, the actual histogram of each image pixel can be computed by changing the computationMode parameter. The first method is faster, while the second is more accurate.




<b> (a) </b>
(a)
<b> (b) </b>
(b)
<b> (c) </b>
(c)
Figure 1. Comparison between standard histogram equalization and CLAHE with related histograms:
(a) the input image to enhance, (b) result of a standard histogram equalization, (c) result of the CLAHE algorithm

The CLAHE algorithm can be sumarized by the following steps: Reference:
K.Zuiderveld. "Contrast Limited Adaptive Histogram Equalization". Graphics Gems IV, pp.474-485, 1994.

See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > clahe2d( std::shared_ptr< iolink::ImageView > inputImage, iolink::Vector2u32 tileSize, Clahe2d::ComputationMode computationMode, double clipLimit, uint32_t numberOfBins, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
clahe_2d(input_image: idt.ImageType,
         tile_size: Iterable[int] = [256, 256],
         computation_mode: Clahe2d.ComputationMode = Clahe2d.ComputationMode.INTERPOLATED,
         clip_limit: float = 1,
         number_of_bins: int = 256,
         output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
Clahe2d( IOLink.ImageView inputImage,
         uint[] tileSize = null,
         Clahe2d.ComputationMode computationMode = ImageDev.Clahe2d.ComputationMode.INTERPOLATED,
         double clipLimit = 1,
         UInt32 numberOfBins = 256,
         IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Grayscale or Multispectral nullptr
input
tileSize
The X and Y size, in pixels, of the tile used to compute the histogram. Vector2u32 Any value {256, 256}
input
computationMode
The way to compute histograms for the transformation function.
INTERPOLATED The image is divided in contiguous tiles. A histogram is calculated for each tile and the transformation function for a given pixel is determined by interpolation of these histograms.
SLIDING A histogram is computed for the tile surrounding each pixel and the transformation function is based on this histogram.
Enumeration INTERPOLATED
input
clipLimit
The ratio defining the maximum number of elements contained in a histogram bin as a multiple of the average histogram contents.
This maximum number of elements is equal to the clip limit multiplied by the number of pixels of a tile divided by the number of bins of the histogram.
  • A clip limit value equals to the number of bins of the histogram means that no contrast amplification limitation is applied.
  • A clip limit value equals to 0 means that the output image the same as the input image.
Float64 >=0 1
input
numberOfBins
The number of bins of the histogram. UInt32 >=1 256
output
outputImage
The output image. The output image characteristics are forced to the same as the input image. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input image. image Grayscale or Multispectral None
input
tile_size
The X and Y size, in pixels, of the tile used to compute the histogram. vector2u32 Any value [256, 256]
input
computation_mode
The way to compute histograms for the transformation function.
INTERPOLATED The image is divided in contiguous tiles. A histogram is calculated for each tile and the transformation function for a given pixel is determined by interpolation of these histograms.
SLIDING A histogram is computed for the tile surrounding each pixel and the transformation function is based on this histogram.
enumeration INTERPOLATED
input
clip_limit
The ratio defining the maximum number of elements contained in a histogram bin as a multiple of the average histogram contents.
This maximum number of elements is equal to the clip limit multiplied by the number of pixels of a tile divided by the number of bins of the histogram.
  • A clip limit value equals to the number of bins of the histogram means that no contrast amplification limitation is applied.
  • A clip limit value equals to 0 means that the output image the same as the input image.
float64 >=0 1
input
number_of_bins
The number of bins of the histogram. uint32 >=1 256
output
output_image
The output image. The output image characteristics are forced to the same as the input image. image None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Grayscale or Multispectral null
input
tileSize
The X and Y size, in pixels, of the tile used to compute the histogram. Vector2u32 Any value {256, 256}
input
computationMode
The way to compute histograms for the transformation function.
INTERPOLATED The image is divided in contiguous tiles. A histogram is calculated for each tile and the transformation function for a given pixel is determined by interpolation of these histograms.
SLIDING A histogram is computed for the tile surrounding each pixel and the transformation function is based on this histogram.
Enumeration INTERPOLATED
input
clipLimit
The ratio defining the maximum number of elements contained in a histogram bin as a multiple of the average histogram contents.
This maximum number of elements is equal to the clip limit multiplied by the number of pixels of a tile divided by the number of bins of the histogram.
  • A clip limit value equals to the number of bins of the histogram means that no contrast amplification limitation is applied.
  • A clip limit value equals to 0 means that the output image the same as the input image.
Float64 >=0 1
input
numberOfBins
The number of bins of the histogram. UInt32 >=1 256
output
outputImage
The output image. The output image characteristics are forced to the same as the input image. Image null

Object Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

Clahe2d clahe2dAlgo;
clahe2dAlgo.setInputImage( polystyrene );
clahe2dAlgo.setTileSize( {128, 128} );
clahe2dAlgo.setComputationMode( Clahe2d::ComputationMode::INTERPOLATED );
clahe2dAlgo.setClipLimit( 3 );
clahe2dAlgo.setNumberOfBins( 256 );
clahe2dAlgo.execute();

std::cout << "outputImage:" << clahe2dAlgo.outputImage()->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

clahe_2d_algo = imagedev.Clahe2d()
clahe_2d_algo.input_image = polystyrene
clahe_2d_algo.tile_size = [128, 128]
clahe_2d_algo.computation_mode = imagedev.Clahe2d.INTERPOLATED
clahe_2d_algo.clip_limit = 3
clahe_2d_algo.number_of_bins = 256
clahe_2d_algo.execute()

print("output_image:", str(clahe_2d_algo.output_image))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

Clahe2d clahe2dAlgo = new Clahe2d
{
    inputImage = polystyrene,
    tileSize = new uint[]{128, 128},
    computationMode = Clahe2d.ComputationMode.INTERPOLATED,
    clipLimit = 3,
    numberOfBins = 256
};
clahe2dAlgo.Execute();

Console.WriteLine( "outputImage:" + clahe2dAlgo.outputImage.ToString() );

Function Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = clahe2d( polystyrene, {128, 128}, Clahe2d::ComputationMode::INTERPOLATED, 3, 256 );

std::cout << "outputImage:" << result->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

result = imagedev.clahe_2d(polystyrene, [128, 128], imagedev.Clahe2d.INTERPOLATED, 3, 256)

print("output_image:", str(result))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

IOLink.ImageView result = Processing.Clahe2d( polystyrene, new uint[]{128, 128}, Clahe2d.ComputationMode.INTERPOLATED, 3, 256 );

Console.WriteLine( "outputImage:" + result.ToString() );