examples/rp/Classifier.cpp
Go to the documentation of this file.
1 #include "RPExamples.h"
2 
3 // TerraLib
4 #include <terralib/geometry.h>
5 #include <terralib/raster.h>
6 #include <terralib/rp.h>
7 
8 // STL
9 #include <map>
10 #include <string>
11 
12 std::vector<te::gm::Polygon*> CreatePolygons(te::rst::Raster* rin)
13 {
14 // create 4 input polygons
15  std::vector<te::gm::Polygon*> pin;
16 
17  double xc = (rin->getExtent()->getUpperRightX() + rin->getExtent()->getLowerLeftX())/2;
18  double yc = (rin->getExtent()->getUpperRightY() + rin->getExtent()->getLowerLeftY())/2;
19 
20 // polygon 0
21  {
23  lr->setPoint(0, rin->getExtent()->getLowerLeftX(), rin->getExtent()->getLowerLeftY()); // lower left
24  lr->setPoint(1, rin->getExtent()->getLowerLeftX(), yc); // upper left
25  lr->setPoint(2, xc, yc); // upper rigth
26  lr->setPoint(3, xc, rin->getExtent()->getLowerLeftY()); // lower rigth
27  lr->setPoint(4, rin->getExtent()->getLowerLeftX(), rin->getExtent()->getLowerLeftY()); // closing
28 
30  pol->push_back(lr);
31 
32  pin.push_back(pol);
33  }
34 
35 // polygon 1
36  {
38  lr->setPoint(0, rin->getExtent()->getLowerLeftX(), yc); // lower left
39  lr->setPoint(1, rin->getExtent()->getLowerLeftX(), rin->getExtent()->getUpperRightY()); // upper left
40  lr->setPoint(2, xc, rin->getExtent()->getUpperRightY()); // upper rigth
41  lr->setPoint(3, xc, yc); // lower rigth
42  lr->setPoint(4, rin->getExtent()->getLowerLeftX(), yc); // closing
43 
45  pol->push_back(lr);
46 
47  pin.push_back(pol);
48  }
49 
50 // polygon 2
51  {
53  lr->setPoint(0, xc, yc); // lower left
54  lr->setPoint(1, xc, rin->getExtent()->getUpperRightY()); // upper left
55  lr->setPoint(2, rin->getExtent()->getUpperRightX(), rin->getExtent()->getUpperRightY()); // upper rigth
56  lr->setPoint(3, rin->getExtent()->getUpperRightX(), yc); // lower rigth
57  lr->setPoint(4, xc, yc); // closing
58 
60  pol->push_back(lr);
61 
62  pin.push_back(pol);
63  }
64 
65 // polygon 3
66  {
68  lr->setPoint(0, xc, rin->getExtent()->getLowerLeftY()); // lower left
69  lr->setPoint(1, xc, yc); // upper left
70  lr->setPoint(2, rin->getExtent()->getUpperRightX(), yc); // upper rigth
71  lr->setPoint(3, rin->getExtent()->getUpperRightX(), rin->getExtent()->getLowerLeftY()); // lower rigth
72  lr->setPoint(4, xc, rin->getExtent()->getLowerLeftY()); // closing
73 
75  pol->push_back(lr);
76 
77  pin.push_back(pol);
78  }
79 
80  return pin;
81 }
82 
84 {
85  try
86  {
87  std::cout << "Classification example using Dummy module." << std::endl << std::endl;
88 
89 // open input raster
90  std::map<std::string, std::string> rinfo;
91  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
92 
94 
95 // create output raster info
96  std::map<std::string, std::string> orinfo;
97  orinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_classified_dummy.tif";
98 
99 // create 4 input polygons
100  std::vector<te::gm::Polygon*> pin = CreatePolygons(rin);
101 
102 // define classification parameters
103 
104 // input parameters
105  te::rp::Classifier::InputParameters algoInputParameters;
106  algoInputParameters.m_inputRasterPtr = rin;
107  algoInputParameters.m_inputRasterBands.push_back(0);
108  algoInputParameters.m_inputRasterBands.push_back(1);
109  algoInputParameters.m_inputRasterBands.push_back(2);
110  algoInputParameters.m_inputPolygons = pin;
111 
112 // link specific parameters with chosen implementation
113  te::rp::ClassifierDummyStrategy::Parameters classifierparameters;
114  classifierparameters.m_dummyParameter = 10;
115 
116  algoInputParameters.m_strategyName = "dummy";
117  algoInputParameters.setClassifierStrategyParams(classifierparameters);
118 
119 // output parameters
120  te::rp::Classifier::OutputParameters algoOutputParameters;
121  algoOutputParameters.m_rInfo = orinfo;
122  algoOutputParameters.m_rType = "GDAL";
123 
124 // execute the algorithm
125  te::rp::Classifier classifierinstance;
126 
127  if(!classifierinstance.initialize(algoInputParameters))
128  throw;
129  if(!classifierinstance.execute(algoOutputParameters))
130  throw;
131 
132 // clean up
133  delete rin;
134  pin.clear();
135 
136  std::cout << "Done!" << std::endl << std::endl;
137  }
138  catch(const std::exception& e)
139  {
140  std::cout << std::endl << "An exception has occurred in DummyClassifier(): " << e.what() << std::endl;
141  }
142  catch(...)
143  {
144  std::cout << std::endl << "An unexpected exception has occurred in DummyClassifier()!" << std::endl;
145  }
146 }
147 
148 // this code is for image segmentation to be used with ISOSegClassifier function
149 std::vector<te::gm::Polygon*> SegmentImage(te::rst::Raster* rin)
150 {
151 // define segmentation parameters
152 
153 // create output raster info
154  std::map<std::string, std::string> orinfo;
155  orinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_segmented.tif";
156 
157 // input parameters
158  te::rp::Segmenter::InputParameters algoInputParameters;
159  algoInputParameters.m_inputRasterPtr = rin;
160  algoInputParameters.m_inputRasterBands.push_back(0);
161  algoInputParameters.m_inputRasterBands.push_back(1);
162  algoInputParameters.m_inputRasterBands.push_back(2);
163 
164 // link specific parameters with chosen implementation
165 // strategy specific parameters (m_minSegmentSize: size of the smallest segment to be created;
166 // m_segmentsSimilarityThreshold: similarity between neighboring segments to merge them or not)
168  segparameters.m_minSegmentSize = 50;
169  segparameters.m_segmentsSimilarityThreshold = 0.15;
170 
171  algoInputParameters.m_strategyName = "RegionGrowingMean";
172  algoInputParameters.setSegStrategyParams(segparameters);
173 
174 // output parameters
175  te::rp::Segmenter::OutputParameters algoOutputParameters;
176  algoOutputParameters.m_rInfo = orinfo;
177  algoOutputParameters.m_rType = "GDAL";
178 
179 // execute the algorithm
180  te::rp::Segmenter seginstance;
181 
182  if(!seginstance.initialize(algoInputParameters)) throw;
183  if(!seginstance.execute(algoOutputParameters )) throw;
184 
185 // export the segmentation into shapefile
186  std::vector<te::gm::Geometry*> geometries;
187  algoOutputParameters.m_outputRasterPtr->vectorize( geometries, 0 );
188 
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]));
192 
193  return polygons;
194 }
195 
197 {
198  try
199  {
200  std::cout << "Classification example using ISOSeg algorithm." << std::endl << std::endl;
201 
202 // first open the input image
203  std::map<std::string, std::string> rinfo;
204  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
205 
207 
208 // create output raster info
209  std::map<std::string, std::string> orinfo;
210  orinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_classified_isoseg.tif";
211 
212 // to apply ISOSeg the image must be segmented
213  std::vector<te::gm::Polygon*> polygons = SegmentImage(rin);
214  // std::vector<te::gm::Geometry*> geometries = CreatePolygons(rin);
215 
216  std::cout << "Segmentation created " << polygons.size() << " polygons" << std::endl;
217 
218 // define classification parameters
219 
220 // input parameters
221  te::rp::Classifier::InputParameters algoInputParameters;
222  algoInputParameters.m_inputRasterPtr = rin;
223  algoInputParameters.m_inputRasterBands.push_back(0);
224  algoInputParameters.m_inputRasterBands.push_back(1);
225  algoInputParameters.m_inputRasterBands.push_back(2);
226  algoInputParameters.m_inputPolygons = polygons;
227 
228 // link specific parameters with chosen implementation
230  classifierparameters.m_acceptanceThreshold = 99.0;
231 
232  algoInputParameters.m_strategyName = "isoseg";
233  algoInputParameters.setClassifierStrategyParams(classifierparameters);
234 
235 // output parameters
236  te::rp::Classifier::OutputParameters algoOutputParameters;
237  algoOutputParameters.m_rInfo = orinfo;
238  algoOutputParameters.m_rType = "GDAL";
239 
240 // execute the algorithm
241  te::rp::Classifier classifierinstance;
242 
243  if(!classifierinstance.initialize(algoInputParameters))
244  throw;
245  if(!classifierinstance.execute(algoOutputParameters))
246  throw;
247 
248 // clean up
249  delete rin;
250 
251  std::cout << "Done!" << std::endl << std::endl;
252  }
253  catch(const std::exception& e)
254  {
255  std::cout << std::endl << "An exception has occurred in ISOSegClassifier(): " << e.what() << std::endl;
256  }
257  catch(...)
258  {
259  std::cout << std::endl << "An unexpected exception has occurred in ISOSegClassifier()!" << std::endl;
260  }
261 }
262 
264 {
265  try
266  {
267  std::cout << "Classification example using MAP algorithm." << std::endl << std::endl;
268 
269 // first open the input image
270  std::map<std::string, std::string> rinfo;
271  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
272 
274 
275 // create output raster info
276  std::map<std::string, std::string> orinfo;
277  orinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_classified_MAP.tif";
278 
279 // Defining the classes samples
280 
282  sampleC1_1.push_back( 20 );
283  sampleC1_1.push_back( 190 );
284  sampleC1_1.push_back( 50 );
285 
287  sampleC1_2.push_back( 143 );
288  sampleC1_2.push_back( 242 );
289  sampleC1_2.push_back( 174 );
290 
292  sampleC1_3.push_back( 81 );
293  sampleC1_3.push_back( 226 );
294  sampleC1_3.push_back( 112 );
295 
297  class1Samples.push_back( sampleC1_1 );
298  class1Samples.push_back( sampleC1_2 );
299  class1Samples.push_back( sampleC1_3 );
300 
302  sampleC2_1.push_back( 255 );
303  sampleC2_1.push_back( 226 );
304  sampleC2_1.push_back( 245 );
305 
307  sampleC2_2.push_back( 168 );
308  sampleC2_2.push_back( 138 );
309  sampleC2_2.push_back( 122 );
310 
312  sampleC2_3.push_back( 179 );
313  sampleC2_3.push_back( 167 );
314  sampleC2_3.push_back( 153 );
315 
317  class2Samples.push_back( sampleC2_1 );
318  class2Samples.push_back( sampleC2_2 );
319  class2Samples.push_back( sampleC2_3 );
320 
322  allClassesSamples->insert(te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCT::value_type(1, class1Samples));
323  allClassesSamples->insert(te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCT::value_type(2, class2Samples));
324 
325 // input parameters
326  te::rp::Classifier::InputParameters algoInputParameters;
327  algoInputParameters.m_inputRasterPtr = rin;
328  algoInputParameters.m_inputRasterBands.push_back(0);
329  algoInputParameters.m_inputRasterBands.push_back(1);
330  algoInputParameters.m_inputRasterBands.push_back(2);
331 
332 // link specific parameters with chosen implementation
333  te::rp::ClassifierMAPStrategy::Parameters classifierparameters;
334  classifierparameters.m_trainSamplesPtr = allClassesSamples;
335 
336  algoInputParameters.m_strategyName = "map";
337  algoInputParameters.setClassifierStrategyParams(classifierparameters);
338 
339 // output parameters
340  te::rp::Classifier::OutputParameters algoOutputParameters;
341  algoOutputParameters.m_rInfo = orinfo;
342  algoOutputParameters.m_rType = "GDAL";
343 
344 // execute the algorithm
345  te::rp::Classifier classifierinstance;
346 
347  if(!classifierinstance.initialize(algoInputParameters))
348  throw;
349  if(!classifierinstance.execute(algoOutputParameters))
350  throw;
351 
352 // clean up
353  delete rin;
354 
355  std::cout << "Done!" << std::endl << std::endl;
356  }
357  catch(const std::exception& e)
358  {
359  std::cout << std::endl << "An exception has occurred in MAPClassifier(): " << e.what() << std::endl;
360  }
361  catch(...)
362  {
363  std::cout << std::endl << "An unexpected exception has occurred in MAPClassifier()!" << std::endl;
364  }
365 }
366 
368 {
369  try
370  {
371  std::cout << "Classification example using ED algorithm." << std::endl << std::endl;
372 
373 // first open the input image
374  std::map<std::string, std::string> rinfo;
375  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
376 
378 
379 // create output raster info
380  std::map<std::string, std::string> orinfo;
381  orinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_classified_ED.tif";
382 
383 // Defining the classes samples
384 
386  sampleC1_1.push_back( 20 );
387  sampleC1_1.push_back( 190 );
388  sampleC1_1.push_back( 50 );
389 
391  sampleC1_2.push_back( 143 );
392  sampleC1_2.push_back( 242 );
393  sampleC1_2.push_back( 174 );
394 
396  sampleC1_3.push_back( 81 );
397  sampleC1_3.push_back( 226 );
398  sampleC1_3.push_back( 112 );
399 
401  class1Samples.push_back( sampleC1_1 );
402  class1Samples.push_back( sampleC1_2 );
403  class1Samples.push_back( sampleC1_3 );
404 
406  sampleC2_1.push_back( 255 );
407  sampleC2_1.push_back( 226 );
408  sampleC2_1.push_back( 245 );
409 
411  sampleC2_2.push_back( 168 );
412  sampleC2_2.push_back( 138 );
413  sampleC2_2.push_back( 122 );
414 
416  sampleC2_3.push_back( 179 );
417  sampleC2_3.push_back( 167 );
418  sampleC2_3.push_back( 153 );
419 
421  class2Samples.push_back( sampleC2_1 );
422  class2Samples.push_back( sampleC2_2 );
423  class2Samples.push_back( sampleC2_3 );
424 
426  allClassesSamples->insert(te::rp::ClassifierEDStrategy::Parameters::MClassesSamplesCT::value_type(1, class1Samples));
427  allClassesSamples->insert(te::rp::ClassifierEDStrategy::Parameters::MClassesSamplesCT::value_type(2, class2Samples));
428 
429 // input parameters
430  te::rp::Classifier::InputParameters algoInputParameters;
431  algoInputParameters.m_inputRasterPtr = rin;
432  algoInputParameters.m_inputRasterBands.push_back(0);
433  algoInputParameters.m_inputRasterBands.push_back(1);
434  algoInputParameters.m_inputRasterBands.push_back(2);
435 
436 // link specific parameters with chosen implementation
437  te::rp::ClassifierEDStrategy::Parameters classifierparameters;
438  classifierparameters.m_trainSamplesPtr = allClassesSamples;
439 
440  algoInputParameters.m_strategyName = "ed";
441  algoInputParameters.setClassifierStrategyParams(classifierparameters);
442 
443 // output parameters
444  te::rp::Classifier::OutputParameters algoOutputParameters;
445  algoOutputParameters.m_rInfo = orinfo;
446  algoOutputParameters.m_rType = "GDAL";
447 
448 // execute the algorithm
449  te::rp::Classifier classifierinstance;
450 
451  if(!classifierinstance.initialize(algoInputParameters))
452  throw;
453  if(!classifierinstance.execute(algoOutputParameters))
454  throw;
455 
456 // clean up
457  delete rin;
458 
459  std::cout << "Done!" << std::endl << std::endl;
460  }
461  catch(const std::exception& e)
462  {
463  std::cout << std::endl << "An exception has occurred in EDClassifier(): " << e.what() << std::endl;
464  }
465  catch(...)
466  {
467  std::cout << std::endl << "An unexpected exception has occurred in EDClassifier()!" << std::endl;
468  }
469 }
470 
472 {
473  try
474  {
475  std::cout << "Classification example using EM (Expectation-Maximization) algorithm." << std::endl << std::endl;
476 
477 // first open the input image
478  std::map<std::string, std::string> rinfo;
479  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
480 
482 
483 // create output raster info
484  std::map<std::string, std::string> orinfo;
485  orinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_classified_em.tif";
486 
487 // define classification parameters
488 
489 // input parameters
490  te::rp::Classifier::InputParameters algoInputParameters;
491  algoInputParameters.m_inputRasterPtr = rin;
492  algoInputParameters.m_inputRasterBands.push_back(0);
493  algoInputParameters.m_inputRasterBands.push_back(1);
494  algoInputParameters.m_inputRasterBands.push_back(2);
495 
496 // link specific parameters with chosen implementation
497  te::rp::ClassifierEMStrategy::Parameters classifierparameters;
498  classifierparameters.m_numberOfClusters = 4;
499  classifierparameters.m_maxIterations = 100;
500  classifierparameters.m_maxInputPoints = 1000;
501  classifierparameters.m_epsilon = 15.0;
502  classifierparameters.m_clustersMeans = std::vector<std::vector<double> >();
503 
504  algoInputParameters.m_strategyName = "em";
505  algoInputParameters.setClassifierStrategyParams(classifierparameters);
506 
507 // output parameters
508  te::rp::Classifier::OutputParameters algoOutputParameters;
509  algoOutputParameters.m_rInfo = orinfo;
510  algoOutputParameters.m_rType = "GDAL";
511 
512 // execute the algorithm
513  te::rp::Classifier classifierinstance;
514 
515  if(!classifierinstance.initialize(algoInputParameters))
516  throw;
517  if(!classifierinstance.execute(algoOutputParameters))
518  throw;
519 
520 // clean up
521  delete rin;
522 
523  std::cout << "Done!" << std::endl << std::endl;
524  }
525  catch(const std::exception& e)
526  {
527  std::cout << std::endl << "An exception has occurred in EMClassifier(): " << e.what() << std::endl;
528  }
529  catch(...)
530  {
531  std::cout << std::endl << "An unexpected exception has occurred in EMClassifier()!" << std::endl;
532  }
533 }
534 
536 {
537  try
538  {
539  std::cout << "Classification example using SAM algorithm." << std::endl << std::endl;
540 
541 // first open the input image
542  std::map<std::string, std::string> rinfo;
543  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
544 
546 
547 // create output raster info
548  std::map<std::string, std::string> orinfo;
549  orinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_classified_SAM.tif";
550 
551 // Defining the classes samples
552 
554  sampleC1_1.push_back( 166 );
555  sampleC1_1.push_back( 255 );
556  sampleC1_1.push_back( 255 );
558  class1Samples.push_back( sampleC1_1 );
559 
561  sampleC2_1.push_back( 36 );
562  sampleC2_1.push_back( 255 );
563  sampleC2_1.push_back( 76 );
565  class2Samples.push_back( sampleC2_1 );
566 
568  sampleC3_1.push_back( 36 );
569  sampleC3_1.push_back( 36 );
570  sampleC3_1.push_back( 76 );
572  class3Samples.push_back( sampleC3_1 );
573 
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));
578 
579 // input parameters
580  te::rp::Classifier::InputParameters algoInputParameters;
581  algoInputParameters.m_inputRasterPtr = rin;
582  algoInputParameters.m_inputRasterBands.push_back(0);
583  algoInputParameters.m_inputRasterBands.push_back(1);
584  algoInputParameters.m_inputRasterBands.push_back(2);
585 
586 // link specific parameters with chosen implementation
587  te::rp::ClassifierSAMStrategy::Parameters classifierparameters;
588  classifierparameters.m_trainSamplesPtr = allClassesSamples;
589  classifierparameters.m_maxAngularDistances.push_back( 0.2 );
590  classifierparameters.m_maxAngularDistances.push_back( 0.2 );
591  classifierparameters.m_maxAngularDistances.push_back( 0.2 );
592 
593  algoInputParameters.m_strategyName = "sam";
594  algoInputParameters.setClassifierStrategyParams(classifierparameters);
595 
596 // output parameters
597  te::rp::Classifier::OutputParameters algoOutputParameters;
598  algoOutputParameters.m_rInfo = orinfo;
599  algoOutputParameters.m_rType = "GDAL";
600 
601 // execute the algorithm
602  te::rp::Classifier classifierinstance;
603 
604  if(!classifierinstance.initialize(algoInputParameters))
605  throw;
606  if(!classifierinstance.execute(algoOutputParameters))
607  throw;
608 
609 // clean up
610  delete rin;
611 
612  std::cout << "Done!" << std::endl << std::endl;
613  }
614  catch(const std::exception& e)
615  {
616  std::cout << std::endl << "An exception has occurred in SAMClassifier(): " << e.what() << std::endl;
617  }
618  catch(...)
619  {
620  std::cout << std::endl << "An unexpected exception has occurred in SAMClassifier()!" << std::endl;
621  }
622 }
623 
625 {
626  try
627  {
628  std::cout << "Classification example using KMeans algorithm." << std::endl << std::endl;
629 
630 // first open the input image
631  std::map<std::string, std::string> rinfo;
632  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
633 
635 
636 // create output raster info
637  std::map<std::string, std::string> orinfo;
638  orinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_classified_kmeans.tif";
639 
640 // define classification parameters
641 
642 // input parameters
643  te::rp::Classifier::InputParameters algoInputParameters;
644  algoInputParameters.m_inputRasterPtr = rin;
645  algoInputParameters.m_inputRasterBands.push_back(0);
646  algoInputParameters.m_inputRasterBands.push_back(1);
647  algoInputParameters.m_inputRasterBands.push_back(2);
648 
649 // link specific parameters with chosen implementation
651  classifierparameters.m_K = 4;
652  classifierparameters.m_maxIterations = 10;
653  classifierparameters.m_epsilon = 15.0;
654 
655  algoInputParameters.m_strategyName = "kmeans";
656  algoInputParameters.setClassifierStrategyParams(classifierparameters);
657 
658 // output parameters
659  te::rp::Classifier::OutputParameters algoOutputParameters;
660  algoOutputParameters.m_rInfo = orinfo;
661  algoOutputParameters.m_rType = "GDAL";
662 
663 // execute the algorithm
664  te::rp::Classifier classifierinstance;
665 
666  if(!classifierinstance.initialize(algoInputParameters))
667  throw;
668  if(!classifierinstance.execute(algoOutputParameters))
669  throw;
670 
671 // clean up
672  delete rin;
673 
674  std::cout << "Done!" << std::endl << std::endl;
675  }
676  catch(const std::exception& e)
677  {
678  std::cout << std::endl << "An exception has occurred in KMeansClassifier(): " << e.what() << std::endl;
679  }
680  catch(...)
681  {
682  std::cout << std::endl << "An unexpected exception has occurred in KMeansClassifier()!" << std::endl;
683  }
684 }
685 
687 {
688  SAMClassifier();
689  DummyClassifier();
691  MAPClassifier();
692  EDClassifier();
693  EMClassifier();
695 }
std::vector< te::gm::Polygon * > m_inputPolygons
The polygons to be classified when using object-based image analysis (OBIA).
Definition: Classifier.h:120
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::string m_strategyName
The segmenter strategy name see each te::rp::SegmenterStrategyFactory inherited classes documentation...
std::map< ClassIDT, SamplesT > ClassesSamplesT
Classes samples container type definition.
Raster classification.
Definition: Classifier.h:65
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.
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: Classifier.h:114
unsigned int m_numberOfClusters
The number of clusters (classes) to estimate in the image.
Raster segmentation.
std::string m_strategyName
The classifier strategy name see each te::rp::ClassifierStrategyFactory inherited classes documentati...
Definition: Classifier.h:121
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.
Definition: Classifier.h:133
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.
void ISOSegClassifier()
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.
Definition: LinearRing.h:53
void MAPClassifier()
std::vector< double > ClassSampleT
Class sample type definition.
void EDClassifier()
void setSegStrategyParams(const SegmenterStrategyParameters &segStratParams)
Set specific segmenter strategy parameters.
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.
te::rst::Raster const * m_inputRasterPtr
Input raster.
This file contains include headers for the TerraLib Raster Processing module.
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
Definition: Classifier.h:119
void EMClassifier()
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.
Definition: Polygon.h:50
unsigned int m_maxIterations
The maximum of iterations (E/M steps) to perform if convergence is not achieved.
void setClassifierStrategyParams(const ClassifierStrategyParameters &p)
Set specific classifier strategy parameters.
void DummyClassifier()
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.
void SAMClassifier()
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).
Definition: Classifier.h:161
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Classifier.h:160
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...
void Classifier()
std::vector< std::vector< double > > m_clustersMeans
The previously estimated means of the clusters (optional).
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
void KMeansClassifier()
std::vector< double > ClassSampleT
Class sample type definition.
Classifier input parameters.
Definition: Classifier.h:75
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.