ContrastEnhancement - Contrast Enhancement

This application is the implementation of the histogram equalization algorithm. It can be used to enhance contrast in an image or to reduce the dynamic of the image without losing too much contrast. It offers several options as a no data value, a contrast limitation factor, a local version of the algorithm and also a mode to equalize the luminance of the image.

Detailed description

This application is the implementation of the histogram equalization algorithm. The idea of the algorithm is to use the whole available dynamic. In order to do so it computes a histogram over the image and then use the whole dynamic: meaning flattening the histogram. That gives us gain for each bin that transform the original histogram into the flat one. This gain is then apply on the original image. The application proposes several options to allow a finer result: - There is an option to limit contrast. We choose to limit the contrast by modifying the original histogram. To do so we clip the histogram at a given height and redistribute equally among the bins the clipped population. Then we add a local version of the algorithm. - It is possible to apply the algorithm on tiles of the image, instead of on the whole image. That gives us gain depending on the value of the pixel and its position in the image. In order to smoothen the result we interpolate the gain between tiles.

Parameters

This section describes in details the parameters available for this application. Table [1] presents a summary of these parameters and the parameters keys to be used in command-line and programming languages. Application key is ContrastEnhancement .

[1]Table: Parameters table for Contrast Enhancement.
Parameter Key Parameter Name Parameter Type
in Input Image Input image
out Output Image Output image
bins Number of bins Int
hfact Contrast Limitation Float
nodata Nodata Value Float
spatial Spatial parameters for the histogram computation Choices
spatial local Local Choice
spatial global Global Choice
spatial.local.h Thumbnail height Int
spatial.local.w Thumbnail width Int
minmax Minimum and maximum settings Choices
minmax auto Automatic Choice
minmax manual Manual settings for min/max values Choice
minmax.auto.global Global Boolean
minmax.manual.min Minimum value Float
minmax.manual.max Maximum value Float
mode What to equalized Choices
mode each Channels Choice
mode lum Luminance Choice
mode.lum.red Red channel Group
mode.lum.red.ch Red channel Int
mode.lum.red.coef Value for luminance computation for the red channel Float
mode.lum.green Green channel Group
mode.lum.green.ch Green channel Int
mode.lum.green.coef Value for luminance computation of the green channel Float
mode.lum.blue Blue channel Group
mode.lum.blue.ch Blue channel Int
mode.lum.blue.coef Value for luminance computation of the blue channel Float
ram Available RAM (Mb) Int
inxml Load otb application from xml file XML input parameters file
outxml Save otb application to xml file XML output parameters file

Input Image: Input image.

Output Image: Output image.

Number of bins: Number of bins in the histogram.

Contrast Limitation: This parameter will set the maximum height accepted in a bin on the input image histogram. The maximum height will be computed as hfact*eqHeight where eqHeight is the height of the theoretical flat histogram. The higher hfact, the higher the contrast. When using ‘luminance mode’, it is recommended to limit this factor to a small value (ex: 4).

Nodata Value: If there is a value in the image that has no visualization meaning, it can be ignored by the algorithm.

Spatial parameters for the histogram computation Available choices are:

  • Local: The histograms will be computed on each thumbnail. Each of the histogram will be equalized and the corresponding gain will be interpolated.
  • Thumbnail height: Height of the thumbnail over which the histogram will be computed. The value is in pixels.
  • Thumbnail width: Width of the thumbnail over which the histogram will be computed. The value is in pixels.
  • Global: The histogram will be computed on the whole image. The equalization will be computed on this histogram.

Minimum and maximum settings: Minimum and maximum value that will bound the histogram and thus the dynamic of the resulting image. Values over those boundaries will be clipped. Available choices are:

  • Automatic: Minimum and maximum value will be computed on the image (nodata value won’t be taken into account) . Each band will have a minimum and a maximum.
  • Global: Min/max computation will result in the same minimum and maximum for all the bands.
  • Manual settings for min/max values: Minimum and maximum value will be set by the user.
  • Minimum value
  • Maximum value

What to equalized Available choices are:

  • Channels: Each channel is equalized independently.
  • Luminance: The relative luminance is computed according to the coefficients.Then the histogram is equalized and the gain is applied to each of the channels. The channel gain will depend on the weight (coef) of the channel in the luminance. Note that default values come from color space theories on how human eyes perceive colors).
  • Red channel
  • Red channel
  • Value for luminance computation for the red channel
  • Green channel
  • Green channel
  • Value for luminance computation of the green channel
  • Blue channel
  • Blue channel
  • Value for luminance computation of the blue channel

Available RAM (Mb): Available memory for processing (in MB).

Load otb application from xml file: Load otb application from xml file.

Save otb application to xml file: Save otb application to xml file.

Example

Local contrast enhancement by luminanceTo run this example in command-line, use the following:

otbcli_ContrastEnhancement -in colours.tif -out equalizedcolors.tif float -bins 256 -spatial.local.w 500 -spatial.local.h 500 -mode lum

To run this example from Python, use the following code snippet:

#!/usr/bin/python

# Import the otb applications package
import otbApplication

# The following line creates an instance of the ContrastEnhancement application
ContrastEnhancement = otbApplication.Registry.CreateApplication("ContrastEnhancement")

# The following lines set all the application parameters:
ContrastEnhancement.SetParameterString("in", "colours.tif")

ContrastEnhancement.SetParameterString("out", "equalizedcolors.tif")
ContrastEnhancement.SetParameterOutputImagePixelType("out", 6)

ContrastEnhancement.SetParameterInt("bins", 256)

ContrastEnhancement.SetParameterInt("spatial.local.w", 500)

ContrastEnhancement.SetParameterInt("spatial.local.h", 500)

ContrastEnhancement.SetParameterString("mode","lum")

# The following line execute the application
ContrastEnhancement.ExecuteAndWriteOutput()

Limitations

None

Authors

This application has been written by OTB-Team.