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.
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.
-in image Mandatory
-out image [dtype] Mandatory
Number of bins
-bins int Default value: 256
Number of bins in the histogram
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)
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
The histograms will be computed on each thumbnail. Each of the histogram will be equalized and the corresponding gain will be interpolated.
The histogram will be computed on the whole image. The equalization will be computed on this histogram.
-spatial.local.h int Default value: 256
Height of the thumbnail over which the histogram will be computed. The value is in pixels.
-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.
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
-minmax.auto.global bool Default value: false
Min/max computation will result in the same minimum and maximum for all the bands.
What to equalized
-mode [each|lum] Default value: each
Each channel is equalized independently
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)
-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
-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
-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).
Load parameters from XML
Load application parameters from an XML file.
Save parameters to XML
Save application parameters to an XML file.
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
# 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()