1
2 ///////////////////////////////////////////////////////////
3 // //
4 // Tool: //
5 // destriping //
6 // //
7 // for SAGA //
8 // System for Automated Geoscientific Analyses //
9 // //
10 //-------------------------------------------------------//
11 // //
12 // destriping2.cpp //
13 // //
14 // //
15 //-------------------------------------------------------//
16 // //
17 // //
18 // by Alessandro Perego (Italy) //
19 // //
20 // e-mail: alper78@alice.it //
21 // //
22 // //
23 ///////////////////////////////////////////////////////////
24
25 //---------------------------------------------------------
26 #include "destriping2.h"
27
28
29 ///////////////////////////////////////////////////////////
30 // //
31 // //
32 // //
33 ///////////////////////////////////////////////////////////
34
35 //---------------------------------------------------------
Cdestriping2(void)36 Cdestriping2::Cdestriping2(void)
37 {
38 Set_Name (_TL("Destriping with Mask"));
39
40 Set_Author ("Alessandro Perego");
41
42 Set_Description (_TW(
43 "Destriping filter removes straight parallel stripes in raster data. "
44 "It uses two low-pass filters elongated in the stripes direction; "
45 "the first one is 1 pixel unit wide while the second one is wide as the striping wavelength. "
46 "Their difference is the striping error which is removed from the original data to obtain the destriped DEM. "
47 "This method is equivalent to that proposed ry[1] Oimoen (2000). "
48 "With destriping 2 you can choose a range of value (min-max) from the input grid "
49 "and a range of value (Mask min - Mask max) from a mask grid to select the target cells. "
50 ));
51
52 Add_Reference("Oimoen, M.J.", "2000",
53 "An Effective Filter For Removal Of Production Artifacts",
54 "In U.S. Geological Survey 7.5-Minute Digital Elevation Models. "
55 "Proceedings of the Fourteenth International Conference on Applied Geologic Remote Sensing, "
56 "6-8 November, Las Vegas, NV.",
57 SG_T("http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.470.4960&rep=rep1&type=pdf"), SG_T("online")
58 );
59
60 Add_Reference("Perego, A.", "2009",
61 "SRTM DEM destriping with SAGA GIS: consequences on drainage network extraction",
62 "alsperGIS - Dati geografici e software per lo studio e la rappresentazione del territorio.",
63 SG_T("http://www.alspergis.altervista.org/software/destriping.html"), SG_T("online")
64 );
65
66 //-----------------------------------------------------
67 Parameters.Add_Grid ("", "INPUT" , _TL("Grid" ), _TL(""), PARAMETER_INPUT);
68 Parameters.Add_Grid ("", "MASK" , _TL("Mask" ), _TL("Mask used to select cells for processing"), PARAMETER_INPUT);
69
70 Parameters.Add_Grid ("", "RESULT3", _TL("Destriped Grid" ), _TL(""), PARAMETER_OUTPUT);
71 Parameters.Add_Grid ("", "RESULT1", _TL("Low-pass 1" ), _TL("Step 1: low-pass of stripe" ), PARAMETER_OUTPUT_OPTIONAL);
72 Parameters.Add_Grid ("", "RESULT2", _TL("Low-pass 2" ), _TL("Step 2: low-pass between stripe and its surroundings" ), PARAMETER_OUTPUT_OPTIONAL);
73 Parameters.Add_Grid ("", "STRIPES", _TL("Stripes" ), _TL("The difference between destriped and original grid" ), PARAMETER_OUTPUT_OPTIONAL);
74
75 Parameters.Add_Double("", "ANG" , _TL("Angle" ), _TL("[Degree], 0 = horizontal, 90 = vertical"));
76 Parameters.Add_Double("", "R" , _TL("Radius" ), _TL("[Cells]"), 20., 1., true);
77 Parameters.Add_Double("", "D" , _TL("Stripes Distance"), _TL("[Cells]"), 2., 2., true);
78
79 Parameters.Add_Double("INPUT", "MIN" , _TL("Minimum" ), _TL(""), -10.);
80 Parameters.Add_Double("INPUT", "MAX" , _TL("Maximum" ), _TL(""), 10.);
81 Parameters.Add_Double("MASK" , "MMIN", _TL("Mask Minimum" ), _TL(""), -10000.);
82 Parameters.Add_Double("MASK" , "MMAX", _TL("Mask Maximum" ), _TL(""), 10000.);
83 }
84
85
86 ///////////////////////////////////////////////////////////
87 // //
88 ///////////////////////////////////////////////////////////
89
90 //---------------------------------------------------------
On_Execute(void)91 bool Cdestriping2::On_Execute(void)
92 {
93 CSG_Grid *pZ = Parameters("INPUT")->asGrid ();
94 double zmin = Parameters( "MIN")->asDouble();
95 double zmax = Parameters( "MAX")->asDouble();
96
97 CSG_Grid *pM = Parameters( "MASK")->asGrid ();
98 double mmin = Parameters( "MMIN")->asDouble();
99 double mmax = Parameters( "MMAX")->asDouble();
100
101 //-----------------------------------------------------
102 CSG_Grid Mask(Get_System(), SG_DATATYPE_Char);
103
104 Mask.Set_NoData_Value(0.);
105
106 for(int y=0; y<Get_NY() && Set_Progress(y); y++)
107 {
108 #pragma omp parallel for
109 for(int x=0; x<Get_NX(); x++)
110 {
111 Mask.Set_Value(x, y,
112 !pZ->is_NoData(x, y) && SG_IS_BETWEEN(zmin, pZ->asDouble(x, y), zmax) &&
113 !pM->is_NoData(x, y) && SG_IS_BETWEEN(mmin, pM->asDouble(x, y), mmax) ? 1. : 0.
114 );
115 }
116 }
117
118 //-----------------------------------------------------
119 SG_RUN_TOOL_ExitOnError("contrib_perego", 5, // Destriping
120 SG_TOOL_PARAMETER_SET("INPUT" , Parameters("INPUT" ))
121 && SG_TOOL_PARAMETER_SET("RESULT1", Parameters("RESULT1"))
122 && SG_TOOL_PARAMETER_SET("RESULT2", Parameters("RESULT2"))
123 && SG_TOOL_PARAMETER_SET("RESULT3", Parameters("RESULT3"))
124 && SG_TOOL_PARAMETER_SET("STRIPES", Parameters("STRIPES"))
125 && SG_TOOL_PARAMETER_SET("ANG" , Parameters("ANG" ))
126 && SG_TOOL_PARAMETER_SET("R" , Parameters("R" ))
127 && SG_TOOL_PARAMETER_SET("D" , Parameters("D" ))
128 && SG_TOOL_PARAMETER_SET("MASK" , &Mask )
129 );
130
131 //-----------------------------------------------------
132 return( true );
133 }
134
135
136 ///////////////////////////////////////////////////////////
137 // //
138 // //
139 // //
140 ///////////////////////////////////////////////////////////
141
142 //---------------------------------------------------------
143