Adaptive Histogram Equalization Image Filter#

Synopsis#

Apply a power law adaptive histogram equalization controlled by the parameters alpha and beta.

The parameter alpha controls how much the filter acts like the classical histogram equalization method (alpha = 0) to how much the filter acts like an unsharp mask (alpha = 1).

The parameter beta controls how much the filter acts like an unsharp mask (beta = 0) to much the filter acts like pass through (beta = 1, with alpha = 1).

The parameter window (or radius) controls the size of the region over which local statistics are calculated.

Results#

Input image

Output image

Input image.

Output image.

Input image histogram

Output image histogram

Input image histogram.

Output image histogram.

Code#

C++#

#include "itkAdaptiveHistogramEqualizationImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

int
main(int argc, char * argv[])
{
  if (argc < 6)
  {
    std::cerr << "Missing parameters." << std::endl;
    std::cerr << "Usage: " << argv[0] << " inputImageFile outputImageFile alpha beta radius" << std::endl;
    return EXIT_FAILURE;
  }

  constexpr unsigned int Dimension = 2;

  using PixelType = unsigned char;
  using ImageType = itk::Image<PixelType, Dimension>;

  const auto input = itk::ReadImage<ImageType>(argv[1]);

  using AdaptiveHistogramEqualizationImageFilterType = itk::AdaptiveHistogramEqualizationImageFilter<ImageType>;
  AdaptiveHistogramEqualizationImageFilterType::Pointer adaptiveHistogramEqualizationImageFilter =
    AdaptiveHistogramEqualizationImageFilterType::New();

  float alpha = std::stod(argv[3]);
  adaptiveHistogramEqualizationImageFilter->SetAlpha(alpha);

  float beta = std::stod(argv[4]);
  adaptiveHistogramEqualizationImageFilter->SetBeta(beta);

  int                                                         radiusSize = std::stoi(argv[5]);
  AdaptiveHistogramEqualizationImageFilterType::ImageSizeType radius;
  radius.Fill(radiusSize);
  adaptiveHistogramEqualizationImageFilter->SetRadius(radius);

  adaptiveHistogramEqualizationImageFilter->SetInput(input);

  adaptiveHistogramEqualizationImageFilter->Update();

  itk::WriteImage(adaptiveHistogramEqualizationImageFilter->GetOutput(), argv[2]);

  return EXIT_SUCCESS;
}

Python#

#!/usr/bin/env python

import itk
import argparse

parser = argparse.ArgumentParser(
    description="Adaptive Histogram Equalization Image Filter."
)
parser.add_argument("input_image")
parser.add_argument("output_image")
parser.add_argument("alpha", type=float)
parser.add_argument("beta", type=float)
parser.add_argument("radius", type=int)
args = parser.parse_args()

Dimension = 2

PixelType = itk.ctype("unsigned char")
ImageType = itk.Image[PixelType, Dimension]

reader = itk.ImageFileReader[ImageType].New()
reader.SetFileName(args.input_image)

histogramEqualization = itk.AdaptiveHistogramEqualizationImageFilter.New(reader)
histogramEqualization.SetAlpha(args.alpha)
histogramEqualization.SetBeta(args.beta)

radius = itk.Size[Dimension]()
radius.Fill(args.radius)
histogramEqualization.SetRadius(radius)

itk.imwrite(histogramEqualization, args.output_image)

Classes demonstrated#

template<typename TImageType, typename TKernel = Neighborhood<bool, TImageType::ImageDimension>>
class AdaptiveHistogramEqualizationImageFilter : public itk::MovingHistogramImageFilter<TImageType, TImageType, TKernel, Function::AdaptiveEqualizationHistogram<TImageType::PixelType, TImageType::PixelType>>

Power Law Adaptive Histogram Equalization.

Histogram equalization modifies the contrast in an image. The AdaptiveHistogramEqualizationImageFilter is a superset of many contrast enhancing filters. By modifying its parameters (alpha, beta, and window), the AdaptiveHistogramEqualizationImageFilter can produce an adaptively equalized histogram or a version of unsharp mask (local mean subtraction). Instead of applying a strict histogram equalization in a window about a pixel, this filter prescribes a mapping function (power law) controlled by the parameters alpha and beta.

The parameter alpha controls how much the filter acts like the classical histogram equalization method (alpha=0) to how much the filter acts like an unsharp mask (alpha=1).

The parameter beta controls how much the filter acts like an unsharp mask (beta=0) to much the filter acts like pass through (beta=1, with alpha=1).

The parameter window controls the size of the region over which local statistics are calculated. The size of the window is controlled by SetRadius the default Radius is 5 in all directions.

By altering alpha, beta and window, a host of equalization and unsharp masking filters is available.

The boundary condition ignores the part of the neighborhood outside the image, and over-weights the valid part of the neighborhood.

For detail description, reference “Adaptive Image Contrast

Enhancement using Generalizations of Histogram Equalization.” J.Alex Stark. IEEE Transactions on

Image Processing, May 2000.

ITK Sphinx Examples:

See itk::AdaptiveHistogramEqualizationImageFilter for additional documentation.