TsMixtureModel.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/unittest/rp/mixture_model/TsMixtureModel.cpp
22 
23  \brief A test suit for the Mixture Model interface.
24 */
25 
26 // TerraLib
27 #include "../Config.h"
28 #include <terralib/rp.h>
29 #include <terralib/raster.h>
30 
31 // Boost
32 #define BOOST_TEST_NO_MAIN
33 #include <boost/test/unit_test.hpp>
34 
35 BOOST_AUTO_TEST_SUITE (mixtureModel_tests)
36 
37 BOOST_AUTO_TEST_CASE(linear_test)
38 {
39  /* First open the input image */
40 
41  std::map<std::string, std::string> rinfo;
42  rinfo["URI"] = TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif";
43 
45 
46  /* Create output raster for linear mixture model */
47 
48  std::map<std::string, std::string> orinfo;
49  orinfo["URI"] = "cbers2b_rgb342_crop_linearMixtureModel.tif";
50 
51  /* Create algorithm parameters */
52 
53  te::rp::MixtureModel::InputParameters mmInputParameters;
54  te::rp::MixtureModel::OutputParameters mmOutputParameters;
55 
56  /* Defining input parameters */
57 
58  mmInputParameters.m_inputRasterPtr = rin;
59  for (unsigned b = 0; b < rin->getNumberOfBands(); b++)
60  mmInputParameters.m_inputRasterBands.push_back(b);
61  mmInputParameters.m_strategyName = "linear";
62 
63  // Defining sensors
64  mmInputParameters.m_inputSensorBands.push_back("CBERS2_CCD_1_BLUE");
65  mmInputParameters.m_inputSensorBands.push_back("CBERS2_CCD_1_GREEN");
66  mmInputParameters.m_inputSensorBands.push_back("CBERS2_CCD_1_RED");
67 
68  /* Link specific parameters with chosen implementation */
69 
71  mmInputParameters.setMixtureModelStrategyParams(lmmParameters);
72 
73  /* Defining endmembers */
74 
75  mmInputParameters.m_components["clouds"].push_back(255.0);
76  mmInputParameters.m_components["clouds"].push_back(184.875);
77  mmInputParameters.m_components["clouds"].push_back(255.0);
78 
79  mmInputParameters.m_components["shadow"].push_back(42.075);
80  mmInputParameters.m_components["shadow"].push_back(24.99);
81  mmInputParameters.m_components["shadow"].push_back(49.98);
82 
83  mmInputParameters.m_components["vegetation"].push_back(99.96);
84  mmInputParameters.m_components["vegetation"].push_back(64.005);
85  mmInputParameters.m_components["vegetation"].push_back(154.02);
86 
87  /* Defining output parameters */
88 
89  mmOutputParameters.m_rInfo = orinfo;
90  mmOutputParameters.m_rType = "GDAL";
91  mmOutputParameters.m_createErrorRaster = true;
92 
93  /* Execute the algorithm */
94 
95  te::rp::MixtureModel algorithmInstance;
96  boost::numeric::ublas::matrix<double> transfMatrix;
97 
98  BOOST_CHECK( algorithmInstance.initialize(mmInputParameters) );
99  BOOST_CHECK(algorithmInstance.generateTransformMatrix(transfMatrix));
100  BOOST_CHECK(transfMatrix.size1() == 4 );
101  BOOST_CHECK(transfMatrix.size2() == 4 );
102  BOOST_CHECK( algorithmInstance.execute(mmOutputParameters) );
103 
104  /* Clean up */
105  delete rin;
106 }
107 
109 {
110  /* First open the input image */
111 
112  std::map<std::string, std::string> rinfo;
113  rinfo["URI"] = TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif";
114 
116 
117  /* Create output raster for PCA mixture model */
118 
119  std::map<std::string, std::string> orinfo;
120  orinfo["URI"] = "cbers2b_rgb342_crop_PCAMixtureModel.tif";
121 
122  /* Create algorithm parameters */
123 
124  te::rp::MixtureModel::InputParameters mmInputParameters;
125  te::rp::MixtureModel::OutputParameters mmOutputParameters;
126 
127  /* Defining input parameters */
128 
129  mmInputParameters.m_inputRasterPtr = rin;
130  for (unsigned b = 0; b < rin->getNumberOfBands(); b++)
131  mmInputParameters.m_inputRasterBands.push_back(b);
132  mmInputParameters.m_strategyName = "pca";
133 
134  // Defining sensors
135  mmInputParameters.m_inputSensorBands.push_back("CBERS2_CCD_1_BLUE");
136  mmInputParameters.m_inputSensorBands.push_back("CBERS2_CCD_1_GREEN");
137  mmInputParameters.m_inputSensorBands.push_back("CBERS2_CCD_1_RED");
138 
139  /* Link specific parameters with chosen implementation */
140 
142  mmInputParameters.setMixtureModelStrategyParams(pcammParameters);
143 
144  /* Defining endmembers */
145 
146  mmInputParameters.m_components["clouds"].push_back(255.0);
147  mmInputParameters.m_components["clouds"].push_back(184.875);
148  mmInputParameters.m_components["clouds"].push_back(255.0);
149 
150  mmInputParameters.m_components["shadow"].push_back(42.075);
151  mmInputParameters.m_components["shadow"].push_back(24.99);
152  mmInputParameters.m_components["shadow"].push_back(49.98);
153 
154  mmInputParameters.m_components["vegetation"].push_back(99.96);
155  mmInputParameters.m_components["vegetation"].push_back(64.005);
156  mmInputParameters.m_components["vegetation"].push_back(154.02);
157 
158  /* Defining output parameters */
159 
160  mmOutputParameters.m_rInfo = orinfo;
161  mmOutputParameters.m_rType = "GDAL";
162  mmOutputParameters.m_createErrorRaster = true;
163 
164  /* Execute the algorithm */
165 
166  te::rp::MixtureModel algorithmInstance;
167  boost::numeric::ublas::matrix<double> transfMatrix;
168 
169  BOOST_CHECK( algorithmInstance.initialize(mmInputParameters) );
170  BOOST_CHECK(algorithmInstance.generateTransformMatrix(transfMatrix));
171  BOOST_CHECK(transfMatrix.size1() == 3);
172  BOOST_CHECK(transfMatrix.size2() == 3);
173  BOOST_CHECK( algorithmInstance.execute(mmOutputParameters) );
174 
175  /* Clean up */
176  delete rin;
177 }
178 
179 BOOST_AUTO_TEST_SUITE_END()
Raster decomposition using mixture model.
Definition: MixtureModel.h:62
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: MixtureModel.h:154
std::vector< std::string > m_inputSensorBands
The names of the sensor/bands.
Definition: MixtureModel.h:113
BOOST_AUTO_TEST_SUITE(mixtureModel_tests) BOOST_AUTO_TEST_CASE(linear_test)
std::string m_strategyName
The mixture model strategy name see each te::rp::MixtureModelStrategyFactory inherited classes docume...
Definition: MixtureModel.h:115
std::map< std::string, std::string > m_rInfo
The necessary information to create the output raster (as described in te::raster::RasterFactory).
Definition: MixtureModel.h:155
MixtureModel input parameters.
Definition: MixtureModel.h:72
int b
Definition: TsRtree.cpp:32
An abstract class for raster data strucutures.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
This file contains include headers for the TerraLib Raster Processing module.
bool generateTransformMatrix(boost::numeric::ublas::matrix< double > &matrix)
Generates a Transform Matrix.
BOOST_AUTO_TEST_CASE(pca_test)
std::map< std::string, std::vector< double > > m_components
A set of endmembers and its radiances.
Definition: MixtureModel.h:114
MixtureModel output parameters.
Definition: MixtureModel.h:127
bool execute(AlgorithmOutputParameters &outputParams)
Executes the mixing model using the parameters defined in inputParams and outputParams.
void setMixtureModelStrategyParams(const StrategyParameters &p)
Set specific mixture model strategy parameters.
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: MixtureModel.h:111
bool m_createErrorRaster
A flag to indicate that output raster will include the error bands.
Definition: MixtureModel.h:162
bool initialize(const AlgorithmInputParameters &inputParams)
Initializes model with paramters defined in inputParams.
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
Definition: MixtureModel.h:112
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.