15 std::vector<te::gm::Polygon*> pin;
87 std::cout <<
"Classification example using Dummy module." << std::endl << std::endl;
90 std::map<std::string, std::string> rinfo;
91 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
96 std::map<std::string, std::string> orinfo;
97 orinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_classified_dummy.tif";
121 algoOutputParameters.
m_rInfo = orinfo;
122 algoOutputParameters.
m_rType =
"GDAL";
127 if(!classifierinstance.
initialize(algoInputParameters))
129 if(!classifierinstance.
execute(algoOutputParameters))
136 std::cout <<
"Done!" << std::endl << std::endl;
138 catch(
const std::exception& e)
140 std::cout << std::endl <<
"An exception has occurred in DummyClassifier(): " << e.what() << std::endl;
144 std::cout << std::endl <<
"An unexpected exception has occurred in DummyClassifier()!" << std::endl;
154 std::map<std::string, std::string> orinfo;
155 orinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_segmented.tif";
176 algoOutputParameters.
m_rInfo = orinfo;
177 algoOutputParameters.
m_rType =
"GDAL";
182 if(!seginstance.
initialize(algoInputParameters))
throw;
183 if(!seginstance.
execute(algoOutputParameters ))
throw;
186 std::vector<te::gm::Geometry*> geometries;
189 std::vector<te::gm::Polygon*> polygons;
190 for (
unsigned i = 0; i < geometries.size(); i++)
191 polygons.push_back(static_cast<te::gm::Polygon*> (geometries[i]));
200 std::cout <<
"Classification example using ISOSeg algorithm." << std::endl << std::endl;
203 std::map<std::string, std::string> rinfo;
204 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
209 std::map<std::string, std::string> orinfo;
210 orinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_classified_isoseg.tif";
213 std::vector<te::gm::Polygon*> polygons =
SegmentImage(rin);
216 std::cout <<
"Segmentation created " << polygons.size() <<
" polygons" << std::endl;
237 algoOutputParameters.
m_rInfo = orinfo;
238 algoOutputParameters.
m_rType =
"GDAL";
243 if(!classifierinstance.
initialize(algoInputParameters))
245 if(!classifierinstance.
execute(algoOutputParameters))
251 std::cout <<
"Done!" << std::endl << std::endl;
253 catch(
const std::exception& e)
255 std::cout << std::endl <<
"An exception has occurred in ISOSegClassifier(): " << e.what() << std::endl;
259 std::cout << std::endl <<
"An unexpected exception has occurred in ISOSegClassifier()!" << std::endl;
267 std::cout <<
"Classification example using MAP algorithm." << std::endl << std::endl;
270 std::map<std::string, std::string> rinfo;
271 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
276 std::map<std::string, std::string> orinfo;
277 orinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_classified_MAP.tif";
282 sampleC1_1.push_back( 20 );
283 sampleC1_1.push_back( 190 );
284 sampleC1_1.push_back( 50 );
287 sampleC1_2.push_back( 143 );
288 sampleC1_2.push_back( 242 );
289 sampleC1_2.push_back( 174 );
292 sampleC1_3.push_back( 81 );
293 sampleC1_3.push_back( 226 );
294 sampleC1_3.push_back( 112 );
297 class1Samples.push_back( sampleC1_1 );
298 class1Samples.push_back( sampleC1_2 );
299 class1Samples.push_back( sampleC1_3 );
302 sampleC2_1.push_back( 255 );
303 sampleC2_1.push_back( 226 );
304 sampleC2_1.push_back( 245 );
307 sampleC2_2.push_back( 168 );
308 sampleC2_2.push_back( 138 );
309 sampleC2_2.push_back( 122 );
312 sampleC2_3.push_back( 179 );
313 sampleC2_3.push_back( 167 );
314 sampleC2_3.push_back( 153 );
317 class2Samples.push_back( sampleC2_1 );
318 class2Samples.push_back( sampleC2_2 );
319 class2Samples.push_back( sampleC2_3 );
322 allClassesSamples->insert(te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCT::value_type(1, class1Samples));
323 allClassesSamples->insert(te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCT::value_type(2, class2Samples));
341 algoOutputParameters.
m_rInfo = orinfo;
342 algoOutputParameters.
m_rType =
"GDAL";
347 if(!classifierinstance.
initialize(algoInputParameters))
349 if(!classifierinstance.
execute(algoOutputParameters))
355 std::cout <<
"Done!" << std::endl << std::endl;
357 catch(
const std::exception& e)
359 std::cout << std::endl <<
"An exception has occurred in MAPClassifier(): " << e.what() << std::endl;
363 std::cout << std::endl <<
"An unexpected exception has occurred in MAPClassifier()!" << std::endl;
371 std::cout <<
"Classification example using ED algorithm." << std::endl << std::endl;
374 std::map<std::string, std::string> rinfo;
375 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
380 std::map<std::string, std::string> orinfo;
381 orinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_classified_ED.tif";
386 sampleC1_1.push_back( 20 );
387 sampleC1_1.push_back( 190 );
388 sampleC1_1.push_back( 50 );
391 sampleC1_2.push_back( 143 );
392 sampleC1_2.push_back( 242 );
393 sampleC1_2.push_back( 174 );
396 sampleC1_3.push_back( 81 );
397 sampleC1_3.push_back( 226 );
398 sampleC1_3.push_back( 112 );
401 class1Samples.push_back( sampleC1_1 );
402 class1Samples.push_back( sampleC1_2 );
403 class1Samples.push_back( sampleC1_3 );
406 sampleC2_1.push_back( 255 );
407 sampleC2_1.push_back( 226 );
408 sampleC2_1.push_back( 245 );
411 sampleC2_2.push_back( 168 );
412 sampleC2_2.push_back( 138 );
413 sampleC2_2.push_back( 122 );
416 sampleC2_3.push_back( 179 );
417 sampleC2_3.push_back( 167 );
418 sampleC2_3.push_back( 153 );
421 class2Samples.push_back( sampleC2_1 );
422 class2Samples.push_back( sampleC2_2 );
423 class2Samples.push_back( sampleC2_3 );
426 allClassesSamples->insert(te::rp::ClassifierEDStrategy::Parameters::MClassesSamplesCT::value_type(1, class1Samples));
427 allClassesSamples->insert(te::rp::ClassifierEDStrategy::Parameters::MClassesSamplesCT::value_type(2, class2Samples));
445 algoOutputParameters.
m_rInfo = orinfo;
446 algoOutputParameters.
m_rType =
"GDAL";
451 if(!classifierinstance.
initialize(algoInputParameters))
453 if(!classifierinstance.
execute(algoOutputParameters))
459 std::cout <<
"Done!" << std::endl << std::endl;
461 catch(
const std::exception& e)
463 std::cout << std::endl <<
"An exception has occurred in EDClassifier(): " << e.what() << std::endl;
467 std::cout << std::endl <<
"An unexpected exception has occurred in EDClassifier()!" << std::endl;
475 std::cout <<
"Classification example using EM (Expectation-Maximization) algorithm." << std::endl << std::endl;
478 std::map<std::string, std::string> rinfo;
479 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
484 std::map<std::string, std::string> orinfo;
485 orinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_classified_em.tif";
502 classifierparameters.
m_clustersMeans = std::vector<std::vector<double> >();
509 algoOutputParameters.
m_rInfo = orinfo;
510 algoOutputParameters.
m_rType =
"GDAL";
515 if(!classifierinstance.
initialize(algoInputParameters))
517 if(!classifierinstance.
execute(algoOutputParameters))
523 std::cout <<
"Done!" << std::endl << std::endl;
525 catch(
const std::exception& e)
527 std::cout << std::endl <<
"An exception has occurred in EMClassifier(): " << e.what() << std::endl;
531 std::cout << std::endl <<
"An unexpected exception has occurred in EMClassifier()!" << std::endl;
539 std::cout <<
"Classification example using SAM algorithm." << std::endl << std::endl;
542 std::map<std::string, std::string> rinfo;
543 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
548 std::map<std::string, std::string> orinfo;
549 orinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_classified_SAM.tif";
554 sampleC1_1.push_back( 166 );
555 sampleC1_1.push_back( 255 );
556 sampleC1_1.push_back( 255 );
558 class1Samples.push_back( sampleC1_1 );
561 sampleC2_1.push_back( 36 );
562 sampleC2_1.push_back( 255 );
563 sampleC2_1.push_back( 76 );
565 class2Samples.push_back( sampleC2_1 );
568 sampleC3_1.push_back( 36 );
569 sampleC3_1.push_back( 36 );
570 sampleC3_1.push_back( 76 );
572 class3Samples.push_back( sampleC3_1 );
575 allClassesSamples->insert(te::rp::ClassifierSAMStrategy::ClassesSamplesT::value_type(1, class1Samples));
576 allClassesSamples->insert(te::rp::ClassifierSAMStrategy::ClassesSamplesT::value_type(2, class2Samples));
577 allClassesSamples->insert(te::rp::ClassifierSAMStrategy::ClassesSamplesT::value_type(3, class3Samples));
598 algoOutputParameters.
m_rInfo = orinfo;
599 algoOutputParameters.
m_rType =
"GDAL";
604 if(!classifierinstance.
initialize(algoInputParameters))
606 if(!classifierinstance.
execute(algoOutputParameters))
612 std::cout <<
"Done!" << std::endl << std::endl;
614 catch(
const std::exception& e)
616 std::cout << std::endl <<
"An exception has occurred in SAMClassifier(): " << e.what() << std::endl;
620 std::cout << std::endl <<
"An unexpected exception has occurred in SAMClassifier()!" << std::endl;
628 std::cout <<
"Classification example using KMeans algorithm." << std::endl << std::endl;
631 std::map<std::string, std::string> rinfo;
632 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
637 std::map<std::string, std::string> orinfo;
638 orinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop_classified_kmeans.tif";
651 classifierparameters.
m_K = 4;
660 algoOutputParameters.
m_rInfo = orinfo;
661 algoOutputParameters.
m_rType =
"GDAL";
666 if(!classifierinstance.
initialize(algoInputParameters))
668 if(!classifierinstance.
execute(algoOutputParameters))
674 std::cout <<
"Done!" << std::endl << std::endl;
676 catch(
const std::exception& e)
678 std::cout << std::endl <<
"An exception has occurred in KMeansClassifier(): " << e.what() << std::endl;
682 std::cout << std::endl <<
"An unexpected exception has occurred in KMeansClassifier()!" << std::endl;
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
void push_back(Curve *ring)
It adds the curve to the curve polygon.
std::map< ClassIDT, SamplesT > ClassesSamplesT
Classes samples container type definition.
MClassesSamplesCTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
boost::shared_ptr< MClassesSamplesCT > MClassesSamplesCTPtr
A shared pointer to a multi classes samples container type definition.
boost::shared_ptr< MClassesSamplesCT > MClassesSamplesCTPtr
A shared pointer to a multi classes samples container type definition.
Segmenter Output Parameters.
unsigned int m_numberOfClusters
The number of clusters (classes) to estimate in the image.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
These routines show how to use the RP (raster processing) module.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT
Multi-classes samples container type definition.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
Classifier output parameters.
boost::shared_ptr< ClassesSamplesT > ClassesSamplesTPtr
A shared pointer to a multi classes samples container type definition.
ClassesSamplesTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
std::vector< double > SampleT
Class sample type definition.
MClassesSamplesCTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
std::vector< te::gm::Polygon * > SegmentImage(te::rst::Raster *rin)
std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT
Multi-classes samples container type definition.
unsigned int m_K
The number of clusters (means) to detect in image.
A LinearRing is a LineString that is both closed and simple.
std::vector< double > ClassSampleT
Class sample type definition.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
An abstract class for raster data strucutures.
This file contains include headers for the TerraLib Raster Processing module.
double m_segmentsSimilarityThreshold
Segments similarity treshold - Use lower values to merge only those segments that are more similar - ...
unsigned int m_minSegmentSize
A positive minimum segment size (pixels number - default: 100).
unsigned int m_maxInputPoints
The maximum number of points used to estimate the clusters (default = 1000).
double m_epsilon
The stop criteria. When the clusters change in a value smaller then epsilon, the convergence is achie...
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
unsigned int m_maxIterations
The maximum of iterations (E/M steps) to perform if convergence is not achieved.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
unsigned int m_dummyParameter
A dummy parameter.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
std::vector< SampleT > SamplesT
Class samples container type definition.
std::vector< te::gm::Polygon * > CreatePolygons(te::rst::Raster *rin)
unsigned int m_maxIterations
The maximum of iterations to perform if convergence is not achieved.
double m_acceptanceThreshold
The acceptance threshold (the closer to 100%, few clusters are created).
This file contains include headers for the Vector Geometry model of TerraLib.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
std::vector< ClassSampleT > ClassSamplesContainerT
Class samples container type definition.
std::vector< ClassSampleT > ClassSamplesContainerT
Class samples container type definition.
std::vector< double > m_maxAngularDistances
This is a vector of maximum acceptable angles (radians) between one pixel spectra and the reference s...
std::vector< std::vector< double > > m_clustersMeans
The previously estimated means of the clusters (optional).
std::vector< double > ClassSampleT
Class sample type definition.
double m_epsilon
The stop criteria. When the clusters change in a value smaller then epsilon, the convergence is achie...
static Raster * open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
It opens a raster with the given parameters and default raster driver.