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 equalized 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. Upon this coarse algorithm we added several option to allow a finer result. First there is the limitation of the contrast. Many ways can be used to do it, 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. 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 bin | 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 in pixel | Int |
spatial.local.w | Thumbnail width in pixel | Int |
minmax | Minimum and maximum definition | Choices |
minmax auto | Automatic | Choice |
minmax manuel | Manuel | Choice |
minmax.auto.global | Global | Boolean |
minmax.manuel.min | Minimum | Float |
minmax.manuel.max | Maximum | 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 | Float |
mode.lum.green | Green Channel | Group |
mode.lum.green.ch | Greenen Channel | Int |
mode.lum.green.coef | Value for luminance computation | Float |
mode.lum.blue | Blue Channel | Group |
mode.lum.blue.ch | Blue Channel | Int |
mode.lum.blue.coef | Value for luminance computation | 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 bin: Number of bin used to create 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.
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 the each thumbnail. Each of the histogram will be equalized and the corresponding gain will be interpolated.
- Thumbnail height in pixel
- Thumbnail width in pixel
- Global: The histogram will be computed on the whole image. The equalization will be done on this single histogram.
Minimum and maximum definition: Minimum and maximum value that will bound the histogram. Available choices are:
- Automatic: Minimum and maximum value will be set by the user.
- Global: AutomaticMin/max computation will result in the same minimum and maximum for all the bands.
- Manuel
- Minimum
- Maximum
What to equalized Available choices are:
- Channels: Each channel is equalized independently.
- Luminance: The luminance is equalized and then a gain is applied on each channels. This gain for each channels will depend onthe weight (coef) of the channel in the luminance.
- Red Channel
- Red Channel
- Value for luminance computation
- Green Channel
- Greenen Channel
- Value for luminance computation
- Blue Channel
- Blue Channel
- Value for luminance computation
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 couleurs.tif -out equalizedcouleurs.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", "couleurs.tif")
ContrastEnhancement.SetParameterString("out", "equalizedcouleurs.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.