TsRasterAttributes.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/functions/TsRasterAttributes.cpp
22 
23  \brief A test suit for the Functions 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 // STL
33 #include <memory>
34 #include <string>
35 
36 // Boost
37 #define BOOST_TEST_NO_MAIN
38 #include <boost/test/unit_test.hpp>
39 #include <boost/lexical_cast.hpp>
40 #include <boost/timer.hpp>
41 
42 BOOST_AUTO_TEST_SUITE (raster_attributes_tests)
43 
44 BOOST_AUTO_TEST_CASE( getGLCMMetrics_test )
45 {
46  /* Openning input raster */
47 
48  std::map<std::string, std::string> auxRasterInfo;
49 
50  auxRasterInfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers_rgb342_crop1.tif";
51  boost::shared_ptr< te::rst::Raster > inputRasterPtrPointer ( te::rst::RasterFactory::open(
52  auxRasterInfo ) );
53  BOOST_CHECK( inputRasterPtrPointer.get() );
54 
55  // raster_attributes_tests
56 
57  te::rp::RasterAttributes attributesInstance( true );
58 
59  boost::numeric::ublas::matrix<double> glcm;
60  glcm = attributesInstance.getGLCM( *inputRasterPtrPointer, 0, 1, 1, 0, 255, 256 );
61 
62  te::rp::Texture glcmMetrics = attributesInstance.getGLCMMetrics( glcm );
63 
64  BOOST_REQUIRE_CLOSE( glcmMetrics.m_contrast, 4.0108956721513795, 0.00001 );
65  BOOST_REQUIRE_CLOSE( glcmMetrics.m_dissimilarity, 1.3006917202426418, 0.00001 );
66  BOOST_REQUIRE_CLOSE( glcmMetrics.m_energy, 0.098389689308334138, 0.00001 );
67  BOOST_REQUIRE_CLOSE( glcmMetrics.m_entropy, 5.1017890175144585, 0.00001 );
68  BOOST_REQUIRE_CLOSE( glcmMetrics.m_homogeneity, 0.53576701787364245, 0.00001 );
69 }
70 
71 BOOST_AUTO_TEST_SUITE_END()
double m_energy
GLCM metric Energy (the square root of Angular Second Moment) ${{i,j=0}^{N-1}P_{i,j}^2}$.
Definition: Texture.h:77
Extraction of attributes from Raster, Bands, and Polygons.
double m_homogeneity
GLCM metric Homogeneity (also called Inverse Difference Moment) ${i,j=0}^{N-1}{P_{i,j}}{1+(i-j)^2}$.
Definition: Texture.h:79
double m_dissimilarity
GLCM metric Dissimilarity ${i,j=0}^{N-1}P_{i,j}|i-j|$.
Definition: Texture.h:76
This file contains include headers for the TerraLib Raster Processing module.
BOOST_AUTO_TEST_SUITE(raster_attributes_tests) BOOST_AUTO_TEST_CASE(getGLCMMetrics_test)
double m_entropy
GLCM metric Entropy ${i,j=0}^{N-1}P_{i,j}(-{P_{i,j}})$.
Definition: Texture.h:78
double m_contrast
GLCM metric Contrast (also called Sum of Squares Variance) ${i,j=0}^{N-1}P_{i,j}(i-j)^2$.
Definition: Texture.h:75
BOOST_AUTO_TEST_CASE(encoding_test_utf8_latin1)
A structure to hold the set of GLCM metrics.
Definition: Texture.h:44
This file contains include headers for the Data Access module of TerraLib.
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.