ContrastEnhancement

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 nodata value, a contrast limitation factor, a local version of the algorithm and also a mode to equalize the luminance of the image.

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

Input Image -in image Mandatory
Input image.

Output Image -out image [dtype] Mandatory
Output image.

Number of bins -bins int Default value: 256
Number of bins in the histogram

Contrast Limitation -hfact float
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 -nodata float
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 -spatial [local|global] Default value: local

  • Local
    The histograms will be computed on each thumbnail. Each of the histogram will be equalized and the corresponding gain will be interpolated.

  • Global
    The histogram will be computed on the whole image. The equalization will be computed on this histogram.

Local options

Thumbnail height -spatial.local.h int Default value: 256
Height of the thumbnail over which the histogram will be computed. The value is in pixels.

Thumbnail width -spatial.local.w int Default value: 256
Width of the thumbnail over which the histogram will be computed. The value is in pixels.


Minimum and maximum settings -minmax [auto|manual] Default value: auto
Minimum and maximum value that will bound the histogram and thus the dynamic of the resulting image. Values over those boundaries will be clipped.

  • 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.

  • Manual settings for min/max values
    Minimum and maximum value will be set by the user

Automatic options

Global -minmax.auto.global bool Default value: false
Min/max computation will result in the same minimum and maximum for all the bands.

Manual settings for min/max values options

Minimum value -minmax.manual.min float

Maximum value -minmax.manual.max float


What to equalized -mode [each|lum] Default value: each

  • 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)

Luminance options

Red channel

Red channel -mode.lum.red.ch int Default value: 0

Value for luminance computation for the red channel -mode.lum.red.coef float Default value: 0.21

Green channel

Green channel -mode.lum.green.ch int Default value: 1

Value for luminance computation of the green channel -mode.lum.green.coef float Default value: 0.71

Blue channel

Blue channel -mode.lum.blue.ch int Default value: 2

Value for luminance computation of the blue channel -mode.lum.blue.coef float Default value: 0.08


Available RAM (MB) -ram int Default value: 256
Available memory for processing (in MB).

Examples

From the command-line:

# Local contrast enhancement by luminance
otbcli_ContrastEnhancement -in colours.tif -out equalizedcolors.tif float -bins 256 -spatial.local.w 500 -spatial.local.h 500 -mode lum

From Python:

# Local contrast enhancement by luminance
import otbApplication

app = otbApplication.Registry.CreateApplication("ContrastEnhancement")

app.SetParameterString("in", "colours.tif")
app.SetParameterString("out", "equalizedcolors.tif")
app.SetParameterOutputImagePixelType("out", 6)
app.SetParameterInt("bins", 256)
app.SetParameterInt("spatial.local.w", 500)
app.SetParameterInt("spatial.local.h", 500)
app.SetParameterString("mode","lum")

app.ExecuteAndWriteOutput()