TsFilter.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/filter/TsFilter.cpp
22 
23  \brief A test suit for the Filter 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 #include <boost/shared_ptr.hpp>
35 
36 BOOST_AUTO_TEST_SUITE (filter_tests)
37 
38 BOOST_AUTO_TEST_CASE(sobelFilter_test)
39 {
40  /* Openning input raster */
41 
42  std::map<std::string, std::string> auxRasterInfo;
43 
44  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
45  boost::shared_ptr< te::rst::Raster > inputRasterPtrPointer ( te::rst::RasterFactory::open(
46  auxRasterInfo ) );
47  BOOST_CHECK( inputRasterPtrPointer.get() );
48 
49  /* Creating the algorithm parameters */
50 
51  te::rp::Filter::InputParameters algoInputParams;
52 
54 
55  algoInputParams.m_inRasterPtr = inputRasterPtrPointer.get();
56 
57  algoInputParams.m_inRasterBands.push_back( 0 );
58  algoInputParams.m_inRasterBands.push_back( 1 );
59  algoInputParams.m_inRasterBands.push_back( 2 );
60 
61  algoInputParams.m_iterationsNumber = 4;
62 
63  te::rp::Filter::OutputParameters algoOutputParams;
64 
65  algoOutputParams.m_rInfo["URI"] = "terralib_unittest_rp_Filter_SobelFilter.tif";
66  algoOutputParams.m_rType = "GDAL";
67 
68  /* Executing the algorithm */
69 
70  te::rp::Filter algorithmInstance;
71 
72  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
73  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
74 }
75 
76 
77 BOOST_AUTO_TEST_CASE(robertsFilter_test)
78 {
79  /* Openning input raster */
80 
81  std::map<std::string, std::string> auxRasterInfo;
82 
83  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
84  boost::shared_ptr< te::rst::Raster > inputRasterPtrPointer ( te::rst::RasterFactory::open(
85  auxRasterInfo ) );
86  BOOST_CHECK( inputRasterPtrPointer.get() );
87 
88  /* Creating the algorithm parameters */
89 
90  te::rp::Filter::InputParameters algoInputParams;
91 
93 
94  algoInputParams.m_inRasterPtr = inputRasterPtrPointer.get();
95 
96  algoInputParams.m_inRasterBands.push_back( 0 );
97  algoInputParams.m_inRasterBands.push_back( 1 );
98  algoInputParams.m_inRasterBands.push_back( 2 );
99 
100  algoInputParams.m_iterationsNumber = 4;
101 
102  te::rp::Filter::OutputParameters algoOutputParams;
103 
104  algoOutputParams.m_rInfo["URI"] = "terralib_unittest_rp_Filter_RobertsFilter.tif";
105  algoOutputParams.m_rType = "GDAL";
106 
107  /* Executing the algorithm */
108 
109  te::rp::Filter algorithmInstance;
110 
111  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
112  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
113 }
114 
115 BOOST_AUTO_TEST_CASE(meanFilter_test)
116 {
117  /* Openning input raster */
118 
119  std::map<std::string, std::string> auxRasterInfo;
120 
121  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
122  boost::shared_ptr< te::rst::Raster > inputRasterPtrPointer ( te::rst::RasterFactory::open(
123  auxRasterInfo ) );
124  BOOST_CHECK( inputRasterPtrPointer.get() );
125 
126  /* Creating the algorithm parameters */
127 
128  te::rp::Filter::InputParameters algoInputParams;
129 
131 
132  algoInputParams.m_inRasterPtr = inputRasterPtrPointer.get();
133 
134  algoInputParams.m_inRasterBands.push_back( 0 );
135  algoInputParams.m_inRasterBands.push_back( 1 );
136  algoInputParams.m_inRasterBands.push_back( 2 );
137 
138  algoInputParams.m_iterationsNumber = 4;
139 
140  te::rp::Filter::OutputParameters algoOutputParams;
141 
142  algoOutputParams.m_rInfo["URI"] = "terralib_unittest_rp_Filter_MeanFilter.tif";
143  algoOutputParams.m_rType = "GDAL";
144 
145  /* Executing the algorithm */
146 
147  te::rp::Filter algorithmInstance;
148 
149  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
150  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
151 }
152 
153 
154 BOOST_AUTO_TEST_CASE(modeFilter_test)
155 {
156  /* Openning input raster */
157 
158  std::map<std::string, std::string> auxRasterInfo;
159 
160  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
161  boost::shared_ptr< te::rst::Raster > inputRasterPtrPointer ( te::rst::RasterFactory::open(
162  auxRasterInfo ) );
163  BOOST_CHECK( inputRasterPtrPointer.get() );
164 
165  /* Creating the algorithm parameters */
166 
167  te::rp::Filter::InputParameters algoInputParams;
168 
170 
171  algoInputParams.m_inRasterPtr = inputRasterPtrPointer.get();
172 
173  algoInputParams.m_inRasterBands.push_back( 0 );
174  algoInputParams.m_inRasterBands.push_back( 1 );
175  algoInputParams.m_inRasterBands.push_back( 2 );
176 
177  algoInputParams.m_iterationsNumber = 4;
178 
179  te::rp::Filter::OutputParameters algoOutputParams;
180 
181  algoOutputParams.m_rInfo["URI"] = "terralib_unittest_rp_Filter_ModeFilter.tif";
182  algoOutputParams.m_rType = "GDAL";
183 
184  /* Executing the algorithm */
185 
186  te::rp::Filter algorithmInstance;
187 
188  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
189  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
190 }
191 
192 BOOST_AUTO_TEST_CASE(medianFilter_test)
193 {
194  /* Openning input raster */
195 
196  std::map<std::string, std::string> auxRasterInfo;
197 
198  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
199  boost::shared_ptr< te::rst::Raster > inputRasterPtrPointer ( te::rst::RasterFactory::open(
200  auxRasterInfo ) );
201  BOOST_CHECK( inputRasterPtrPointer.get() );
202 
203  /* Creating the algorithm parameters */
204 
205  te::rp::Filter::InputParameters algoInputParams;
206 
208 
209  algoInputParams.m_inRasterPtr = inputRasterPtrPointer.get();
210 
211  algoInputParams.m_inRasterBands.push_back( 0 );
212  algoInputParams.m_inRasterBands.push_back( 1 );
213  algoInputParams.m_inRasterBands.push_back( 2 );
214 
215  algoInputParams.m_iterationsNumber = 4;
216 
217  te::rp::Filter::OutputParameters algoOutputParams;
218 
219  algoOutputParams.m_rInfo["URI"] = "terralib_unittest_rp_Filter_MedianFilter.tif";
220  algoOutputParams.m_rType = "GDAL";
221 
222  /* Executing the algorithm */
223 
224  te::rp::Filter algorithmInstance;
225 
226  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
227  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
228 }
229 
230 BOOST_AUTO_TEST_CASE(dilationFilter_test)
231 {
232  /* Openning input raster */
233 
234  std::map<std::string, std::string> auxRasterInfo;
235 
236  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
237  boost::shared_ptr< te::rst::Raster > inputRasterPtrPointer ( te::rst::RasterFactory::open(
238  auxRasterInfo ) );
239  BOOST_CHECK( inputRasterPtrPointer.get() );
240 
241  /* Creating the algorithm parameters */
242 
243  te::rp::Filter::InputParameters algoInputParams;
244 
246 
247  algoInputParams.m_inRasterPtr = inputRasterPtrPointer.get();
248 
249  algoInputParams.m_inRasterBands.push_back( 0 );
250  algoInputParams.m_inRasterBands.push_back( 1 );
251  algoInputParams.m_inRasterBands.push_back( 2 );
252 
253  algoInputParams.m_iterationsNumber = 4;
254 
255  algoInputParams.m_window = boost::numeric::ublas::matrix<double>( 3, 3, 1.0 );
256 
257  te::rp::Filter::OutputParameters algoOutputParams;
258 
259  algoOutputParams.m_rInfo["URI"] = "terralib_unittest_rp_Filter_DilationFilter.tif";
260  algoOutputParams.m_rType = "GDAL";
261 
262  /* Executing the algorithm */
263 
264  te::rp::Filter algorithmInstance;
265 
266  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
267  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
268 }
269 
270 BOOST_AUTO_TEST_CASE(erosionFilter_test)
271 {
272  /* Openning input raster */
273 
274  std::map<std::string, std::string> auxRasterInfo;
275 
276  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
277  boost::shared_ptr< te::rst::Raster > inputRasterPtrPointer ( te::rst::RasterFactory::open(
278  auxRasterInfo ) );
279  BOOST_CHECK( inputRasterPtrPointer.get() );
280 
281  /* Creating the algorithm parameters */
282 
283  te::rp::Filter::InputParameters algoInputParams;
284 
286 
287  algoInputParams.m_inRasterPtr = inputRasterPtrPointer.get();
288 
289  algoInputParams.m_inRasterBands.push_back( 0 );
290  algoInputParams.m_inRasterBands.push_back( 1 );
291  algoInputParams.m_inRasterBands.push_back( 2 );
292 
293  algoInputParams.m_iterationsNumber = 4;
294 
295  algoInputParams.m_window = boost::numeric::ublas::matrix<double>( 3, 3, 1.0 );
296 
297  te::rp::Filter::OutputParameters algoOutputParams;
298 
299  algoOutputParams.m_rInfo["URI"] = "terralib_unittest_rp_Filter_ErosionFilter.tif";
300  algoOutputParams.m_rType = "GDAL";
301 
302  /* Executing the algorithm */
303 
304  te::rp::Filter algorithmInstance;
305 
306  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
307  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
308 }
309 
310 BOOST_AUTO_TEST_CASE(userDefinedWindow_test)
311 {
312  /* Openning input raster */
313 
314  std::map<std::string, std::string> auxRasterInfo;
315 
316  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
317  boost::shared_ptr< te::rst::Raster > inputRasterPtrPointer ( te::rst::RasterFactory::open(
318  auxRasterInfo ) );
319  BOOST_CHECK( inputRasterPtrPointer.get() );
320 
321  /* Creating the algorithm parameters */
322 
323  boost::numeric::ublas::matrix<double> window(3, 3);
324  window(0, 0) = 1;
325  window(0, 1) = 2;
326  window(0, 2) = 1;
327  window(1, 0) = 0;
328  window(1, 1) = 0;
329  window(1, 2) = 0;
330  window(2, 0) = -1;
331  window(2, 1) = -2;
332  window(2, 2) = -1;
333 
334  te::rp::Filter::InputParameters algoInputParams;
335 
337 
338  algoInputParams.m_inRasterPtr = inputRasterPtrPointer.get();
339 
340  algoInputParams.m_inRasterBands.push_back( 0 );
341  algoInputParams.m_inRasterBands.push_back( 1 );
342  algoInputParams.m_inRasterBands.push_back( 2 );
343 
344  algoInputParams.m_iterationsNumber = 1;
345 
346  algoInputParams.m_window = window;
347 
348  te::rp::Filter::OutputParameters algoOutputParams;
349 
350  algoOutputParams.m_rInfo["URI"] = "terralib_unittest_rp_Filter_UserDefinedWindow.tif";
351  algoOutputParams.m_rType = "GDAL";
352 
353  /* Executing the algorithm */
354 
355  te::rp::Filter algorithmInstance;
356 
357  BOOST_CHECK( algorithmInstance.initialize( algoInputParams ) );
358  BOOST_CHECK( algorithmInstance.execute( algoOutputParams ) );
359 }
360 
361 BOOST_AUTO_TEST_SUITE_END()
The resultant pixel will be the mode of pixels in the convolution window. When the window is multimod...
Definition: rp/Filter.h:66
The resultant pixel will be the mean of pixels in the convolution window.
Definition: rp/Filter.h:65
BOOST_AUTO_TEST_SUITE(filter_tests) BOOST_AUTO_TEST_CASE(sobelFilter_test)
Definition: TsFilter.cpp:36
The resultant pixel will be the lowest pixel value in the convolution window.
Definition: rp/Filter.h:69
bool execute(AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
Executes the algorithm using the supplied parameters.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: rp/Filter.h:113
std::vector< unsigned int > m_inRasterBands
Bands to be used from the input raster 1.
Definition: rp/Filter.h:77
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Definition: rp/Filter.h:115
The resultant pixel will be the median of pixels in the convolution window.
Definition: rp/Filter.h:67
unsigned int m_iterationsNumber
The number of iterations to perform (default:1).
Definition: rp/Filter.h:79
The resultant pixel will be the highest pixel value in the convolution window.
Definition: rp/Filter.h:68
BOOST_AUTO_TEST_CASE(robertsFilter_test)
Definition: TsFilter.cpp:77
This file contains include headers for the TerraLib Raster Processing module.
A series of well-known filtering algorithms for images, linear and non-linear..
Definition: rp/Filter.h:47
Filter input parameters.
Definition: rp/Filter.h:55
FilterType m_filterType
The edge filter type.
Definition: rp/Filter.h:73
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: rp/Filter.h:75
bool initialize(const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
Initialize the algorithm instance making it ready for execution.
Filter output parameters.
Definition: rp/Filter.h:109
boost::numeric::ublas::matrix< double > m_window
User defined convolution window. (The size must be equal to m_windowH x m_windowW. Default: an empty matrix)
Definition: rp/Filter.h:87
The user will define the weights of a convolution window.
Definition: rp/Filter.h:70
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.