27 #include "../Config.h" 36 #define BOOST_TEST_NO_MAIN 37 #include <boost/test/unit_test.hpp> 38 #include <boost/timer.hpp> 44 std::vector<
double >& polsValues )
49 std::map<std::string, std::string> orinfo;
50 orinfo[
"URI"] =
"cbers2b_rgb342_crop_segmented.tif";
72 algoOutputParameters.
m_rInfo = orinfo;
73 algoOutputParameters.
m_rType =
"GDAL";
79 if(!seginstance.
initialize(algoInputParameters))
throw;
80 if(!seginstance.
execute(algoOutputParameters ))
throw;
83 std::vector<te::gm::Geometry*> geometries;
84 algoOutputParameters.
m_outputRasterPtr->vectorize( geometries, 0, 0, &polsValues );
86 for (
unsigned i = 0; i < geometries.size(); i++)
88 polygons.push_back(static_cast<te::gm::Polygon*> (geometries[i]));
92 void saveToShp( std::vector<te::gm::Polygon*> polygons, std::vector< double >& polygonsValues,
93 const std::string& shpBaseFileName )
95 std::unique_ptr<te::da::DataSetType> dataSetTypePtr1(
new te::da::DataSetType(shpBaseFileName));
102 std::unique_ptr<te::da::DataSetType> dataSetTypePtr2(
new te::da::DataSetType( *dataSetTypePtr1 ) );
104 std::unique_ptr< te::mem::DataSet > memDataSetPtr(
new te::mem::DataSet( dataSetTypePtr1.get()) );
106 for(
unsigned int polygonsIdx = 0 ; polygonsIdx < polygons.size() ; ++polygonsIdx )
109 dsItemPtr->
setDouble( 0, polygonsValues[ polygonsIdx ] );
113 memDataSetPtr->add( dsItemPtr );
116 remove( ( shpBaseFileName +
".shx" ).c_str() );
117 remove( ( shpBaseFileName +
".shp" ).c_str() );
118 remove( ( shpBaseFileName +
".prj" ).c_str() );
119 remove( ( shpBaseFileName +
".dbf" ).c_str() );
121 std::string connInfo(
"file://" + shpBaseFileName +
".shp");
126 memDataSetPtr->moveBeforeFirst();
128 te::da::Create(dsOGR.get(), dataSetTypePtr2.get(), memDataSetPtr.get());
139 std::map<std::string, std::string> rinfo;
140 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers_rgb342_crop3_EPSG_22522.tif";
144 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers_rgb342_crop2.tif";
149 std::vector<te::gm::Polygon*> pin;
150 std::vector< double > polsValues;
152 saveToShp( pin, polsValues,
"terralib_unittest_rp_Classifier_ISOSeg_Single_Thread_Test" );
182 std::map<std::string, std::string> orinfo;
184 "terralib_unittest_rp_Classifier_ISOSeg_Single_Thread_Mahalanobis_Test.tif";
187 algoOutputParameters.
m_rInfo = orinfo;
188 algoOutputParameters.
m_rType =
"GDAL";
194 BOOST_CHECK( algorithmInstance.
initialize(algoInputParameters) );
197 BOOST_CHECK( algorithmInstance.
execute(algoOutputParameters) );
198 std::cout << std::endl <<
"ISOSeg Mahalanobis single thread execution time: " << timer.elapsed() << std::endl;
210 std::map<std::string, std::string> orinfo;
212 "terralib_unittest_rp_Classifier_ISOSeg_Single_Thread_Bhattacharyya_Test.tif";
215 algoOutputParameters.
m_rInfo = orinfo;
216 algoOutputParameters.
m_rType =
"GDAL";
222 BOOST_CHECK( algorithmInstance.
initialize(algoInputParameters) );
223 BOOST_CHECK( algorithmInstance.
execute(algoOutputParameters) );
233 std::map<std::string, std::string> rinfo;
234 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers_rgb342_crop3_EPSG_22522.tif";
238 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers_rgb342_crop2.tif";
243 std::vector<te::gm::Polygon*> pin;
244 std::vector< double > polsValues;
246 saveToShp( pin, polsValues,
"terralib_unittest_rp_Classifier_ISOSeg_Multi_Thread_Test" );
277 std::map<std::string, std::string> orinfo;
279 "terralib_unittest_rp_Classifier_ISOSeg_Multi_Thread_Mahalanobis_Test.tif";
282 algoOutputParameters.
m_rInfo = orinfo;
283 algoOutputParameters.
m_rType =
"GDAL";
289 BOOST_CHECK( algorithmInstance.
initialize(algoInputParameters) );
292 BOOST_CHECK( algorithmInstance.
execute(algoOutputParameters) );
293 std::cout << std::endl <<
"ISOSeg Mahalanobis multi thread execution time: " << timer.elapsed() << std::endl;
303 std::map<std::string, std::string> rinfo;
304 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers_rgb342_crop1.tif";
310 std::map<std::string, std::string> orinfo;
311 orinfo[
"URI"] =
"terralib_unittest_rp_Classifier_MAP_Test.tif";
316 sampleC1_1.push_back( 41 );
317 sampleC1_1.push_back( 212 );
318 sampleC1_1.push_back( 81 );
321 sampleC1_2.push_back( 38 );
322 sampleC1_2.push_back( 213 );
323 sampleC1_2.push_back( 76 );
326 sampleC1_3.push_back( 42 );
327 sampleC1_3.push_back( 128 );
328 sampleC1_3.push_back( 70 );
331 sampleC1_4.push_back( 31 );
332 sampleC1_4.push_back( 159 );
333 sampleC1_4.push_back( 59 );
336 class1Samples.push_back( sampleC1_1 );
337 class1Samples.push_back( sampleC1_2 );
338 class1Samples.push_back( sampleC1_3 );
339 class1Samples.push_back( sampleC1_4 );
342 sampleC2_1.push_back( 39 );
343 sampleC2_1.push_back( 36 );
344 sampleC2_1.push_back( 81 );
347 sampleC2_2.push_back( 35 );
348 sampleC2_2.push_back( 41 );
349 sampleC2_2.push_back( 72 );
352 sampleC2_3.push_back( 39 );
353 sampleC2_3.push_back( 42 );
354 sampleC2_3.push_back( 76 );
357 sampleC2_4.push_back( 38 );
358 sampleC2_4.push_back( 38 );
359 sampleC2_4.push_back( 77 );
362 class2Samples.push_back( sampleC2_1 );
363 class2Samples.push_back( sampleC2_2 );
364 class2Samples.push_back( sampleC2_3 );
365 class2Samples.push_back( sampleC2_4 );
368 allClassesSamples->insert(te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCT::value_type(1, class1Samples));
369 allClassesSamples->insert(te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCT::value_type(2, class2Samples));
396 algoOutputParameters.
m_rInfo = orinfo;
397 algoOutputParameters.
m_rType =
"GDAL";
403 BOOST_CHECK( algorithmInstance.
initialize(algoInputParameters) );
404 BOOST_CHECK( algorithmInstance.
execute(algoOutputParameters) );
416 std::map<std::string, std::string> rinfo;
417 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
423 std::map<std::string, std::string> orinfo;
424 orinfo[
"URI"] =
"terralib_unittest_rp_Classifier_ED_Test.tif";
429 sampleC1_1.push_back( 20 );
430 sampleC1_1.push_back( 190 );
431 sampleC1_1.push_back( 50 );
434 sampleC1_2.push_back( 143 );
435 sampleC1_2.push_back( 242 );
436 sampleC1_2.push_back( 174 );
439 sampleC1_3.push_back( 81 );
440 sampleC1_3.push_back( 226 );
441 sampleC1_3.push_back( 112 );
444 class1Samples.push_back( sampleC1_1 );
445 class1Samples.push_back( sampleC1_2 );
446 class1Samples.push_back( sampleC1_3 );
449 sampleC2_1.push_back( 255 );
450 sampleC2_1.push_back( 226 );
451 sampleC2_1.push_back( 245 );
454 sampleC2_2.push_back( 168 );
455 sampleC2_2.push_back( 138 );
456 sampleC2_2.push_back( 122 );
459 sampleC2_3.push_back( 179 );
460 sampleC2_3.push_back( 167 );
461 sampleC2_3.push_back( 153 );
464 class2Samples.push_back( sampleC2_1 );
465 class2Samples.push_back( sampleC2_2 );
466 class2Samples.push_back( sampleC2_3 );
469 allClassesSamples->insert(te::rp::ClassifierEDStrategy::Parameters::MClassesSamplesCT::value_type(1, class1Samples));
470 allClassesSamples->insert(te::rp::ClassifierEDStrategy::Parameters::MClassesSamplesCT::value_type(2, class2Samples));
497 algoOutputParameters.
m_rInfo = orinfo;
498 algoOutputParameters.
m_rType =
"GDAL";
504 BOOST_CHECK( algorithmInstance.
initialize(algoInputParameters) );
505 BOOST_CHECK( algorithmInstance.
execute(algoOutputParameters) );
517 std::map<std::string, std::string> rinfo;
518 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
524 std::map<std::string, std::string> orinfo;
525 orinfo[
"URI"] =
"terralib_unittest_rp_Classifier_EM_Test.tif";
544 classifierparameters.
m_clustersMeans = std::vector<std::vector<double> >();
556 algoOutputParameters.
m_rInfo = orinfo;
557 algoOutputParameters.
m_rType =
"GDAL";
563 BOOST_CHECK( algorithmInstance.
initialize(algoInputParameters) );
564 BOOST_CHECK( algorithmInstance.
execute(algoOutputParameters) );
576 std::map<std::string, std::string> rinfo;
577 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
583 std::map<std::string, std::string> orinfo;
584 orinfo[
"URI"] =
"terralib_unittest_rp_Classifier_SAM_Test.tif";
589 sampleC1_1.push_back( 166 );
590 sampleC1_1.push_back( 255 );
591 sampleC1_1.push_back( 255 );
593 class1Samples.push_back( sampleC1_1 );
596 sampleC2_1.push_back( 36 );
597 sampleC2_1.push_back( 255 );
598 sampleC2_1.push_back( 76 );
600 class2Samples.push_back( sampleC2_1 );
603 sampleC3_1.push_back( 36 );
604 sampleC3_1.push_back( 36 );
605 sampleC3_1.push_back( 76 );
607 class3Samples.push_back( sampleC3_1 );
610 allClassesSamples->insert(te::rp::ClassifierSAMStrategy::ClassesSamplesT::value_type(1, class1Samples));
611 allClassesSamples->insert(te::rp::ClassifierSAMStrategy::ClassesSamplesT::value_type(2, class2Samples));
612 allClassesSamples->insert(te::rp::ClassifierSAMStrategy::ClassesSamplesT::value_type(3, class3Samples));
641 algoOutputParameters.
m_rInfo = orinfo;
642 algoOutputParameters.
m_rType =
"GDAL";
648 BOOST_CHECK( algorithmInstance.
initialize(algoInputParameters) );
649 BOOST_CHECK( algorithmInstance.
execute(algoOutputParameters) );
661 std::map<std::string, std::string> rinfo;
662 rinfo[
"URI"] = TERRALIB_DATA_DIR
"/geotiff/cbers2b_rgb342_crop.tif";
668 std::map<std::string, std::string> orinfo;
669 orinfo[
"URI"] =
"terralib_unittest_rp_Classifier_KMeans_Test.tif";
684 classifierparameters.
m_K = 4;
699 algoOutputParameters.
m_rInfo = orinfo;
700 algoOutputParameters.
m_rType =
"GDAL";
706 BOOST_CHECK( algorithmInstance.
initialize(algoInputParameters) );
707 BOOST_CHECK( algorithmInstance.
execute(algoOutputParameters) );
713 BOOST_AUTO_TEST_SUITE_END()
std::map< ClassIDT, SamplesT > ClassesSamplesT
Classes samples container type definition.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
MClassesSamplesCTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
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.
This file contains include headers for the memory data source of TerraLib.
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
Segmenter Output Parameters.
An atomic property like an integer or double.
void saveToShp(std::vector< te::gm::Polygon * > polygons, std::vector< double > &polygonsValues, const std::string &shpBaseFileName)
BOOST_AUTO_TEST_CASE(ISOSeg_single_thread_test)
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.
A class that models the description of a dataset.
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.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
unsigned int m_maxInputPoints
The maximum number of points used to estimate the clusters (default = 1000).
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.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
std::vector< double > ClassSampleT
Class sample type definition.
Bhattacharyya Distance Type.
An abstract class for raster data strucutures.
TEDATAACCESSEXPORT void Create(DataSource *ds, DataSetType *dt, DataSet *d, std::size_t limit=0)
It creates the dataset definition in a data source and then fill it with data from the input dataset...
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).
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Mahalanobis Distance Type.
DistanceType m_distanceType
Distance type.
double m_epsilon
The stop criteria. When the clusters change in a value smaller then epsilon, the convergence is achie...
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
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.
std::vector< SampleT > SamplesT
Class samples container type definition.
unsigned int m_maxIterations
The maximum of iterations to perform if convergence is not achieved.
This file contains include headers for the TerraLib Common Runtime module.
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.
BOOST_AUTO_TEST_SUITE(classifier_tests) void SegmentImage(te
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
This file contains include headers for the Data Access module of TerraLib.
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.