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>;

  using FileReaderType = itk::ImageFileReader<ImageType>;
  FileReaderType::Pointer reader = FileReaderType::New();
  reader->SetFileName(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(reader->GetOutput());

  adaptiveHistogramEqualizationImageFilter->Update();

  using WriterType = itk::ImageFileWriter<ImageType>;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(argv[2]);
  writer->SetInput(adaptiveHistogramEqualizationImageFilter->GetOutput());

  writer->Update();

  return EXIT_SUCCESS;
}

Python

#!/usr/bin/env python

import sys
import itk

if len(sys.argv) != 6:
    print('Usage: ' + sys.argv[0] + ' <InputFileName> <OutputFileName> <Alpha> <Beta> <Radius>')
    sys.exit(1)

inputFileName = sys.argv[1]
outputFileName = sys.argv[2]
alpha = float(sys.argv[3])
beta = float(sys.argv[4])
radiusValue = int(sys.argv[5])

Dimension = 2

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

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

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

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

itk.imwrite(histogramEqualization, outputFileName)

Classes demonstrated