File: TePDIHaralick_test.cpp

package info (click to toggle)
libterralib 4.3.0%2Bdfsg.2-10
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 61,560 kB
  • ctags: 37,110
  • sloc: cpp: 225,052; ansic: 31,562; makefile: 807; sh: 80; xml: 37
file content (108 lines) | stat: -rw-r--r-- 3,179 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#define TEAGN_ENABLE_STDOUT_LOG

#include <TePDIExamplesBase.hpp>

#include <TePDIHaralick.hpp>
#include <TePDIParameters.hpp>
#include <TeAgnostic.h>

#include <TeInitRasterDecoders.h>
#include <TeRaster.h>
#include <TeProgress.h>
#include <TeStdIOProgress.h>
#include <TeBox.h>

void numeric_test_with_polygonset()
{
  /* Building synthetic raster */
  
  TePDITypes::TePDIRasterPtrType input_raster( new TeRaster(
    std::string( TEPDIEXAMPLESRESPATH "cbers_b2_crop.tif" ), 'r' ) );
  TEAGN_TRUE_OR_THROW( input_raster->init(), "Unable to init inRaster" );
  
  TePDIParameters pars;
  
  pars.SetParameter( "input_raster", input_raster );
  
  /* Building a polygon set based on the raster bounding box */
  
  TeBox box = input_raster->params().boundingBox();
  TePolygon pol = polygonFromBox( box );
  TePDITypes::TePDIPolygonSetPtrType polset( new TePolygonSet );
  polset->add( pol );
  pars.SetParameter( "polygonset", polset );
  
  pars.SetParameter( "direction", TePDIHaralick::East );
  
  /* Starting algorithm */
  
  TePDIHaralick algoinstance;    
  double value = 0;

  TEAGN_TRUE_OR_THROW( algoinstance.Reset( pars ), "Reset error" );
  
  TEAGN_TRUE_OR_THROW( algoinstance.getGLCMEntropy( 0, 0, value ), 
    "Error generation value" )
  TEAGN_CHECK_EPS( value, 5.314640, 0.00001, "Invalid value" );


  TEAGN_TRUE_OR_THROW( algoinstance.getGLCMEnergy( 0, 0, value ), 
    "Error generation value" )
  TEAGN_CHECK_EPS( value, 0.007787, 0.00001, "Invalid value" );


  TEAGN_TRUE_OR_THROW( algoinstance.getGLCMContrast( 0, 0, value ), 
    "Error generation value" )
  TEAGN_CHECK_EPS( value, 3.765557, 0.00001, "Invalid value" );


  TEAGN_TRUE_OR_THROW( algoinstance.getGLCMHomogeneity( 0, 0, value ), 
    "Error generation value" )
  TEAGN_CHECK_EPS( value, 0.572850, 0.00001, "Invalid value" );


  TEAGN_TRUE_OR_THROW( algoinstance.getGLCMQuiSquare( 0, 0, value ), 
    "Error generation value" )
  TEAGN_CHECK_EPS( value, 30.240689, 0.00001, "Invalid value" );
  
  TEAGN_TRUE_OR_THROW( algoinstance.getGLCMMean( 0, 0, value ), 
    "Error generation value" )
  TEAGN_CHECK_EPS( value, 76.925340, 0.00001, "Invalid value" );  
  
  TEAGN_TRUE_OR_THROW( algoinstance.getGLCMDissimilarity( 0, 0, value ), 
    "Error generation value" )
  TEAGN_CHECK_EPS( value, 1.163392, 0.00001, "Invalid value" );   
   
  TEAGN_TRUE_OR_THROW( algoinstance.getGLCMStdDev( 0, 0, value ), 
    "Error generation value" )
  TEAGN_CHECK_EPS( value, 8.770714, 0.00001, "Invalid value" );   
  
  TEAGN_TRUE_OR_THROW( algoinstance.getGLCMCorrelation( 0, 0, value ), 
    "Error generation value" )
  TEAGN_CHECK_EPS( value, 0.955870, 0.00001, "Invalid value" );   
  
}




int main()
{
  TEAGN_LOGMSG( "Test started." );

  try{
    TeStdIOProgress pi;
    TeProgress::setProgressInterf( dynamic_cast< TeProgressBase* >( &pi ) );
      
    TeInitRasterDecoders();

    numeric_test_with_polygonset();
  }
  catch( const TeException& excpt ){
    TEAGN_LOGERR( excpt.message() )
    return EXIT_FAILURE;
  }

  TEAGN_LOGMSG( "Test OK." );
  return EXIT_SUCCESS;
}