TsContrast.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/contrast/TsContrast.cpp
22 
23  \brief A test suit for the Contrast interface.
24 */
25 
26 // TerraLib
27 #include "../Config.h"
28 #include <terralib/rp.h>
29 #include <terralib/raster.h>
30 #include <terralib/dataaccess.h>
31 
32 // Boost
33 #define BOOST_TEST_NO_MAIN
34 #include <boost/test/unit_test.hpp>
35 #include <boost/shared_ptr.hpp>
36 
37 BOOST_AUTO_TEST_SUITE (contrast_tests)
38 
39 BOOST_AUTO_TEST_CASE(linearContrast_test)
40 {
41  /* Open input raster */
42 
43  std::map<std::string, std::string> inputRasterInfo;
44  inputRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
45 
46  boost::shared_ptr< te::rst::Raster > inputRasterPointer( te::rst::RasterFactory::open(
47  inputRasterInfo ) );
48  BOOST_CHECK( inputRasterPointer.get() );
49 
50  /* Access a raster datasource to create the output raster */
51 
52  std::map<std::string, std::string> outputRasterInfo;
53  outputRasterInfo["URI"] = "terralib_unittest_rp_Contrast_LinearnoOptimization_Test.tif";
54 
55  /* Creating the algorithm parameters */
56 
57  te::rp::Contrast::InputParameters algoInputParams;
58  te::rp::Contrast::OutputParameters algoOutputParams;
59 
61  algoInputParams.m_lCMinInput.resize( 3, 50 );
62  algoInputParams.m_lCMaxInput.resize( 3, 200 );
63  algoInputParams.m_inRasterPtr = inputRasterPointer.get();
64  algoInputParams.m_inRasterBands.push_back( 0 );
65  algoInputParams.m_inRasterBands.push_back( 1 );
66  algoInputParams.m_inRasterBands.push_back( 2 );
67  algoOutputParams.m_createdOutRasterInfo = outputRasterInfo;
68  algoOutputParams.m_createdOutRasterDSType = "GDAL";
69 
70  /* Executing the algorithm */
71 
72  te::rp::Contrast algorithmInstance;
73  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
74  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
75 }
76 
77 BOOST_AUTO_TEST_CASE(histogramEqualizationContrast_test)
78 {
79  /* Open input raster */
80 
81  std::map<std::string, std::string> inputRasterInfo;
82  inputRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
83 
84  boost::shared_ptr< te::rst::Raster > inputRasterPointer( te::rst::RasterFactory::open(
85  inputRasterInfo ) );
86  BOOST_CHECK( inputRasterPointer.get() );
87 
88  /* Access a raster datasource to create the output raster */
89 
90  std::map<std::string, std::string> outputRasterInfo;
91  outputRasterInfo["URI"] = "terralib_unittest_rp_HistogramEqualizationContrast_Test.tif";
92 
93  /* Creating the algorithm parameters */
94 
95  te::rp::Contrast::InputParameters algoInputParams;
96  te::rp::Contrast::OutputParameters algoOutputParams;
97 
99  algoInputParams.m_hECMaxInput.resize( 3, 255 ); // set this parameter to normalize raster [0, 255]
100  algoInputParams.m_inRasterPtr = inputRasterPointer.get();
101  algoInputParams.m_inRasterBands.push_back( 0 );
102  algoInputParams.m_inRasterBands.push_back( 1 );
103  algoInputParams.m_inRasterBands.push_back( 2 );
104  algoOutputParams.m_createdOutRasterInfo = outputRasterInfo;
105  algoOutputParams.m_createdOutRasterDSType = "GDAL";
106 
107  /* Executing the algorithm */
108 
109  te::rp::Contrast algorithmInstance;
110 
111  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
112  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
113 }
114 
115 BOOST_AUTO_TEST_CASE(histogramEqualizationContrastFloat_test)
116 {
117  /* Open input raster */
118 
119  std::map<std::string, std::string> inputRasterInfo;
120  inputRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop_linearMixtureModel_double.tif";
121 
122  boost::shared_ptr< te::rst::Raster > inputRasterPointer( te::rst::RasterFactory::open(
123  inputRasterInfo ) );
124  BOOST_CHECK( inputRasterPointer.get() );
125 
126  /* Access a raster datasource to create the output raster */
127 
128  std::map<std::string, std::string> outputRasterInfo;
129  outputRasterInfo["URI"] = "terralib_unittest_rp_HistogramEqualizationContrastFloat_Test.tif";
130 
131  /* Creating the algorithm parameters */
132 
133  te::rp::Contrast::InputParameters algoInputParams;
134  te::rp::Contrast::OutputParameters algoOutputParams;
135 
137  algoInputParams.m_hECMaxInput.resize( 3, 255 ); // set this parameter to normalize raster [0, 255]
138  algoInputParams.m_inRasterPtr = inputRasterPointer.get();
139  algoInputParams.m_inRasterBands.push_back( 0 );
140  algoInputParams.m_inRasterBands.push_back( 1 );
141  algoInputParams.m_inRasterBands.push_back( 2 );
142  algoOutputParams.m_createdOutRasterInfo = outputRasterInfo;
143  algoOutputParams.m_createdOutRasterDSType = "GDAL";
144 
145  /* Executing the algorithm */
146 
147  te::rp::Contrast algorithmInstance;
148 
149  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
150  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
151 }
152 
153 BOOST_AUTO_TEST_CASE(squareContrast_test)
154 {
155  /* Open input raster */
156 
157  std::map<std::string, std::string> inputRasterInfo;
158  inputRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
159 
160  boost::shared_ptr< te::rst::Raster > inputRasterPointer( te::rst::RasterFactory::open(
161  inputRasterInfo ) );
162  BOOST_CHECK( inputRasterPointer.get() );
163 
164  /* Access a raster datasource to create the output raster */
165 
166  std::map<std::string, std::string> outputRasterInfo;
167  outputRasterInfo["URI"] = "terralib_unittest_rp_Contrast_SquareContrast_Test.tif";
168 
169  /* Creating the algorithm parameters */
170 
171  te::rp::Contrast::InputParameters algoInputParams;
172  te::rp::Contrast::OutputParameters algoOutputParams;
173 
175  algoInputParams.m_squareCMinInput.resize( 3, 50 );
176  algoInputParams.m_squareCMaxInput.resize( 3, 200 );
177  algoInputParams.m_inRasterPtr = inputRasterPointer.get();
178  algoInputParams.m_inRasterBands.push_back( 0 );
179  algoInputParams.m_inRasterBands.push_back( 1 );
180  algoInputParams.m_inRasterBands.push_back( 2 );
181  algoOutputParams.m_createdOutRasterInfo = outputRasterInfo;
182  algoOutputParams.m_createdOutRasterDSType = "GDAL";
183 
184  /* Executing the algorithm */
185 
186  te::rp::Contrast algorithmInstance;
187  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
188  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
189 }
190 
191 BOOST_AUTO_TEST_CASE(squareRootContrast_test)
192 {
193  /* Open input raster */
194 
195  std::map<std::string, std::string> inputRasterInfo;
196  inputRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
197 
198  boost::shared_ptr< te::rst::Raster > inputRasterPointer( te::rst::RasterFactory::open(
199  inputRasterInfo ) );
200  BOOST_CHECK( inputRasterPointer.get() );
201 
202  /* Access a raster datasource to create the output raster */
203 
204  std::map<std::string, std::string> outputRasterInfo;
205  outputRasterInfo["URI"] = "terralib_unittest_rp_Contrast_SquareRootContrast_Test.tif";
206 
207  /* Creating the algorithm parameters */
208 
209  te::rp::Contrast::InputParameters algoInputParams;
210  te::rp::Contrast::OutputParameters algoOutputParams;
211 
213  algoInputParams.m_squareRootCMinInput.resize( 3, 50 );
214  algoInputParams.m_squareRootCMaxInput.resize( 3, 200 );
215  algoInputParams.m_inRasterPtr = inputRasterPointer.get();
216  algoInputParams.m_inRasterBands.push_back( 0 );
217  algoInputParams.m_inRasterBands.push_back( 1 );
218  algoInputParams.m_inRasterBands.push_back( 2 );
219  algoOutputParams.m_createdOutRasterInfo = outputRasterInfo;
220  algoOutputParams.m_createdOutRasterDSType = "GDAL";
221 
222  /* Executing the algorithm */
223 
224  te::rp::Contrast algorithmInstance;
225  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
226  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
227 }
228 
229 BOOST_AUTO_TEST_CASE(logContrast_test)
230 {
231  /* Open input raster */
232 
233  std::map<std::string, std::string> inputRasterInfo;
234  inputRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
235 
236  boost::shared_ptr< te::rst::Raster > inputRasterPointer( te::rst::RasterFactory::open(
237  inputRasterInfo ) );
238  BOOST_CHECK( inputRasterPointer.get() );
239 
240  /* Access a raster datasource to create the output raster */
241 
242  std::map<std::string, std::string> outputRasterInfo;
243  outputRasterInfo["URI"] = "terralib_unittest_rp_Contrast_LogContrast_Test.tif";
244 
245  /* Creating the algorithm parameters */
246 
247  te::rp::Contrast::InputParameters algoInputParams;
248  te::rp::Contrast::OutputParameters algoOutputParams;
249 
251  algoInputParams.m_logCMinInput.resize( 3, 50 );
252  algoInputParams.m_logCMaxInput.resize( 3, 200 );
253  algoInputParams.m_inRasterPtr = inputRasterPointer.get();
254  algoInputParams.m_inRasterBands.push_back( 0 );
255  algoInputParams.m_inRasterBands.push_back( 1 );
256  algoInputParams.m_inRasterBands.push_back( 2 );
257  algoOutputParams.m_createdOutRasterInfo = outputRasterInfo;
258  algoOutputParams.m_createdOutRasterDSType = "GDAL";
259 
260  /* Executing the algorithm */
261 
262  te::rp::Contrast algorithmInstance;
263  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
264  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
265 }
266 
267 BOOST_AUTO_TEST_CASE(setMeanAndStdContrast_test)
268 {
269  /* Open input raster */
270 
271  std::map<std::string, std::string> inputRasterInfo;
272  inputRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
273 
274  boost::shared_ptr< te::rst::Raster > inputRasterPointer( te::rst::RasterFactory::open(
275  inputRasterInfo ) );
276  BOOST_CHECK( inputRasterPointer.get() );
277 
278  /* Access a raster datasource to create the output raster */
279 
280  std::map<std::string, std::string> outputRasterInfo;
281  outputRasterInfo["URI"] = "terralib_unittest_rp_SetMeanAndStdContrast_Test.tif";
282 
283  /* Creating the algorithm parameters */
284 
285  te::rp::Contrast::InputParameters algoInputParams;
286  te::rp::Contrast::OutputParameters algoOutputParams;
287 
289  algoInputParams.m_sMASCMeanInput.resize( 3, 127 );
290  algoInputParams.m_sMASCStdInput.resize( 3, 100 );
291  algoInputParams.m_inRasterPtr = inputRasterPointer.get();
292  algoInputParams.m_inRasterBands.push_back( 0 );
293  algoInputParams.m_inRasterBands.push_back( 1 );
294  algoInputParams.m_inRasterBands.push_back( 2 );
295  algoOutputParams.m_createdOutRasterInfo = outputRasterInfo;
296  algoOutputParams.m_createdOutRasterDSType = "GDAL";
297 
298  /* Executing the algorithm */
299 
300  te::rp::Contrast algorithmInstance;
301  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
302  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
303 }
304 
305 BOOST_AUTO_TEST_CASE(decorrelationEnhancementTContrast_test)
306 {
307  /* Open input raster */
308 
309  std::map<std::string, std::string> inputRasterInfo;
310  inputRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
311 
312  boost::shared_ptr< te::rst::Raster > inputRasterPointer( te::rst::RasterFactory::open(
313  inputRasterInfo ) );
314  BOOST_CHECK( inputRasterPointer.get() );
315 
316  /* Access a raster datasource to create the output raster */
317 
318  std::map<std::string, std::string> outputRasterInfo;
319  outputRasterInfo["URI"] = "terralib_unittest_rp_Contrast_DecorrelationEnhancement_Test.tif";
320 
321  /* Creating the algorithm parameters */
322 
323  te::rp::Contrast::InputParameters algoInputParams;
324  te::rp::Contrast::OutputParameters algoOutputParams;
325 
327  algoInputParams.m_inRasterPtr = inputRasterPointer.get();
328  algoInputParams.m_inRasterBands.push_back( 0 );
329  algoInputParams.m_inRasterBands.push_back( 1 );
330  algoInputParams.m_inRasterBands.push_back( 2 );
331  algoOutputParams.m_createdOutRasterInfo = outputRasterInfo;
332  algoOutputParams.m_createdOutRasterDSType = "GDAL";
333 
334  /* Executing the algorithm */
335 
336  te::rp::Contrast algorithmInstance;
337  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
338  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
339 }
340 
341 BOOST_AUTO_TEST_SUITE_END()
std::vector< double > m_logCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:150
std::vector< double > m_lCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:106
ContrastType m_type
The contrast type to be applied.
Definition: Contrast.h:87
std::vector< double > m_squareRootCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:137
std::vector< double > m_squareRootCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:139
std::vector< double > m_logCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:148
BOOST_AUTO_TEST_CASE(histogramEqualizationContrast_test)
Definition: TsContrast.cpp:77
Contrast input parameters.
Definition: Contrast.h:65
This file contains include headers for the TerraLib Raster Processing module.
std::vector< unsigned int > m_inRasterBands
Bands to be processed from the input raster.
Definition: Contrast.h:91
std::vector< double > m_hECMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:117
std::vector< double > m_sMASCStdInput
The standard deviation to be applied in each band.
Definition: Contrast.h:161
std::vector< double > m_squareCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:128
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
std::vector< double > m_lCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:108
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
std::vector< double > m_sMASCMeanInput
The mean greyscale to be applied in each band.
Definition: Contrast.h:159
std::string m_createdOutRasterDSType
Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the resul...
Definition: Contrast.h:198
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: Contrast.h:89
BOOST_AUTO_TEST_SUITE(contrast_tests) BOOST_AUTO_TEST_CASE(linearContrast_test)
Definition: TsContrast.cpp:37
This file contains include headers for the Data Access module of TerraLib.
Contrast output parameters.
Definition: Contrast.h:188
std::map< std::string, std::string > m_createdOutRasterInfo
The necessary information to create the raster (as described in te::raster::RasterFactory), leave empty if the result must be written to the raster pointed m_outRasterPtr.
Definition: Contrast.h:200
Contrast enhancement.
Definition: Contrast.h:57
std::vector< double > m_squareCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:126
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.