====== RP → Contrast ======
This module implements methods to apply contrast enhancement on the selected bands of a raster.
Input:
* One [[wiki:designimplementation:raster|Raster]]
* A vector of band indices where the contrast will be applied.
The available methods in TerraLib are:
* [[#Linear]]
* [[#Histogram Equalization]]
* [[#Set Mean and Std]]
Dependencies: [[wiki:designimplementation:raster|Raster]]
===== Linear =====
The user defines a new minimum and maximum values for the pixels in the image. The algorithm then applies a linear function over the pixels using this 2 values.
{{:wiki:designimplementation:rp:linear-contrast.png?600|}}
==== Example of use ====
To create an image with a linear contrast, the following parameters are necessary:
// ... (set input data)
// link specific parameters with chosen implementation
te::rp::Contrast::InputParameters contInputParameters;
contInputParameters.m_type = te::rp::Contrast::InputParameters::LinearContrastT;
contInputParameters.m_lCMinInput.push_back(100);
contInputParameters.m_lCMaxInput.push_back(200);
contInputParameters.m_inRasterPtr = rin;
for (unsigned b = 0; b < rin->getNumberOfBands(); b++)
contInputParameters.m_inRasterBands.push_back(b);
// ... (set output data and start algorithm)
===== Histogram Equalization =====
Using this method, the histogram of the image will be equalized automatically.
==== Example of use ====
To create an image with an equalization of histogram contrast, the following parameters are necessary:
// ... (set input data)
// link specific parameters with chosen implementation
te::rp::Contrast::InputParameters contInputParameters;
contInputParameters.m_type = te::rp::Contrast::InputParameters::HistogramEqualizationContrastT;
contInputParameters.m_hECMaxInput.push_back(255); // set this parameter to normalize raster [0, 255]
contInputParameters.m_inRasterPtr = rin;
for (unsigned b = 0; b < rin->getNumberOfBands(); b++)
contInputParameters.m_inRasterBands.push_back(b);
// ... (set output data and start algorithm)
===== Set Mean and Std =====
The contrasted image will have a predefined mean and standard deviation, defined by the user.
==== Example of use ====
To create an image with a predefined mean and standard deviation, the following parameters are necessary:
// ... (set input data)
// link specific parameters with chosen implementation
te::rp::Contrast::InputParameters contInputParameters;
contInputParameters.m_type = te::rp::Contrast::InputParameters::SetMeanAndStdContrastT;
contInputParameters.m_inRasterPtr = rin;
for (unsigned b = 0; b < rin->getNumberOfBands(); b++)
{
contInputParameters.m_inRasterBands.push_back(b);
contInputParameters.m_sMASCMeanInput.push_back(127);
contInputParameters.m_sMASCStdInput.push_back(100);
}
// ... (set output data and start algorithm)
====== From theory to practice ======
The following code shows how to create an image with linear contrast:
// open input raster
std::map rinfo;
rinfo["URI"] = "input.tif";
te::rst::Raster* rin = te::rst::RasterFactory::open(rinfo);
// link specific parameters with chosen implementation
te::rp::Contrast::InputParameters contInputParameters;
contInputParameters.m_type = te::rp::Contrast::InputParameters::LinearContrastT;
contInputParameters.m_inRasterPtr = rin;
for (unsigned b = 0; b < rin->getNumberOfBands(); b++)
{
contInputParameters.m_inRasterBands.push_back(b);
contInputParameters.m_lCMinInput.push_back(100);
contInputParameters.m_lCMaxInput.push_back(200);
}
// set output raster for linear contrast
std::map orinfo;
orinfo["URI"] = "output-linear-contrast.tif";
te::rp::Contrast::OutputParameters contOutputParameters;
contOutputParameters.m_createdOutRasterInfo = orinfo;
contOutputParameters.m_createdOutRasterDSType = "GDAL";
// execute the algorithm
te::rp::Contrast continstance;
bool initok = continstance.initialize(contInputParameters);
if (initok)
continstance.execute(contOutputParameters);
// clean up
delete rin;