RP → Segmenter

Image segmentation covers techniques for splitting one image into its components as homogeneous regions.

Input:

  • One Raster
  • A vector of band indices used to perform segmentation.

Output:

  • One Raster with a single band, where the pixel value stands for the index of the region to which it belongs. It can be transformed to a vector of Polygons using the method te::gdal::Vectorize.

The available method in TerraLib is:

The following methods will be implemented in TerraLib:

Dependencies: Raster, Geometry

Region Growing

Creates regions by merging similar neighboring pixels. To reduce processing time, the raster is divided into pieces, and such pieces are segmented individually.

Algorithm parameters:

  • m_minSegmentSize: size of the smallest segment to be created
  • m_segmentsSimilarityThreshold: similarity between neighboring segments to merge them or not

References:

Example of use

To make a segmentation using Region Growing algorithm, the following parameters are necessary:

// ... (set input data)
 
// link specific parameters with chosen implementation
te::rp::SegmenterRegionGrowingStrategy::Parameters segparameters;
segparameters.m_minSegmentSize = 50;
segparameters.m_segmentsSimilarityThreshold = 30;
 
algoInputParameters.m_strategyName = "regiongrowing";
algoInputParameters.setSegStrategyParams(segparameters);
 
// ... (set output data and start algorithm)

Based on Baatz and Shape, 2000

Creates regions by merging similar neighboring pixels. The resultant regions must fit a predefined scale and compactness, provided by the user.

Algorithm parameters:

  • Compactness Weight: Related to how close to a rectangle will be the output regions.
  • Color Weight: The influence of spectral properties to compute if pixels are similar.
  • Scale Parameter: Related to the size of the output regions.

References:

Example of use

To make a segmentation using Baatz and Shape algorithm, the following parameters are necessary:

// ... (set input data)
 
// link specific parameters with chosen implementation
te::rp::SegmenterRegionGrowingStrategy::Parameters segparameters;
segparameters.m_compactness = 0.5;
segparameters.m_color = 0.3;
segparameters.m_scale = 60;
 
algoInputParameters.m_strategyName = "baatz";
algoInputParameters.setSegStrategyParams(segparameters);
 
// ... (set output data and start algorithm)

<color red>Code under development!!!</color>

Based on Self Organizing Maps

This algorithm performs pixel-based classification using a geographic approach of the Self-Organizing Maps algorithm. Then neighboring pixels of the same class define the regions.

References:

Example of use

To make a segmentation using Self Organizing Maps algorithm, the following parameters are necessary:

// ... (set input data)
 
// link specific parameters with chosen implementation
te::rp::SegmenterRegionGrowingStrategy::Parameters segparameters;
segparameters.m_mapHeight = 3;
segparameters.m_mapWidth = 4;
segparameters.m_radius = 20;
segparameters.m_alpha = 50;
segparameters.m_K = 30;
 
algoInputParameters.m_strategyName = "som";
algoInputParameters.setSegStrategyParams(segparameters);
 
// ... (set output data and start algorithm)

<color red>Code under development!!!</color>

From theory to practice

The following code shows how to perform a segmentation using Region Growing method.

// open input raster
std::map<std::string, std::string> rinfo;
rinfo["URI"] = "input.tif";
te::rst::Raster* rin = te::rst::RasterFactory::open(rinfo);
 
// define segmentation parameters
 
// input parameters
te::rp::Segmenter::InputParameters algoInputParameters;
algoInputParameters.m_inputRasterPtr = rin;
algoInputParameters.m_inputRasterBands.push_back(0);
algoInputParameters.m_inputRasterBands.push_back(1);
algoInputParameters.m_inputRasterBands.push_back(2);
 
// link specific parameters with chosen implementation
te::rp::SegmenterRegionGrowingStrategy::Parameters segparameters;
segparameters.m_minSegmentSize = 50;
segparameters.m_segmentsSimilarityThreshold = 30;
 
algoInputParameters.m_strategyName = "regiongrowing";
algoInputParameters.setSegStrategyParams(segparameters);
 
// output parameters
te::rp::Segmenter::OutputParameters algoOutputParameters;
std::map<std::string, std::string> orinfo;
orinfo["URI"] = "output-segmentation.tif";
algoOutputParameters.m_rInfo = orinfo;
algoOutputParameters.m_rType = "GDAL";
 
// execute the algorithm
te::rp::Segmenter seginstance;
bool initok = seginstance.initialize(algoInputParameters);
if(initok)
  seginstance.execute(algoOutputParameters);
 
// clean up
delete rin;

QR Code
QR Code wiki:designimplementation:rp:segmenter (generated for current page)