svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataset / TestStatistics.java @ 11930
History | View | Annotate | Download (6.31 KB)
1 |
/*
|
---|---|
2 |
* Created on 9-ago-2006
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*/
|
25 |
package org.gvsig.raster.dataset; |
26 |
|
27 |
import junit.framework.TestCase; |
28 |
|
29 |
import org.gvsig.raster.RasterLibrary; |
30 |
import org.gvsig.raster.dataset.properties.DatasetStatistics; |
31 |
|
32 |
/**
|
33 |
* Este test prueba el calculo de estadisticas de un dataset.
|
34 |
* Comprueba que los valores obtenidos en las estadisticas son correctos.
|
35 |
*
|
36 |
*
|
37 |
* Algunos costes del calculo de estadistica en el raster completo
|
38 |
*
|
39 |
* Ordenador: AMD Athlon(tm) XP 1800+ 1540MHz, 256KB Cach?, 500M RAM
|
40 |
* Coste 1:
|
41 |
* Raster: 17910x16062, 275M (GTiff), 1 Banda byte
|
42 |
* Tiempo: 74.295 segs (sgtes igual)
|
43 |
* Coste 2:
|
44 |
* Raster: 8955x8031, 69M (GTiff), 1 Banda byte
|
45 |
* Tiempo: 18.905 segs (sgtes 3.362s)
|
46 |
* Coste 3:
|
47 |
* Raster: 812x586, 2.8M (GTiff), 3 Banda short
|
48 |
* Tiempo: 0.925 segs (sgtes 0.152s)
|
49 |
* Coste 4:
|
50 |
* Raster: 870x870, 210K (Jpeg), 3 Banda byte
|
51 |
* Tiempo: 0.318 segs (sgtes 0.255s)
|
52 |
*
|
53 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
54 |
*
|
55 |
*/
|
56 |
public class TestStatistics extends TestCase { |
57 |
|
58 |
private String baseDir = "./test-images/"; |
59 |
private String path1 = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg"; |
60 |
private String path2 = baseDir + "wcs16bits.tif"; |
61 |
|
62 |
private RasterDataset f1 = null; |
63 |
private RasterDataset f2 = null; |
64 |
private DatasetStatistics stats1 = null; |
65 |
private DatasetStatistics stats2 = null; |
66 |
|
67 |
static {
|
68 |
RasterLibrary.wakeUp(); |
69 |
} |
70 |
|
71 |
public void start() { |
72 |
this.setUp();
|
73 |
this.testStack();
|
74 |
} |
75 |
|
76 |
public void setUp() { |
77 |
System.err.println("TestStatistics running..."); |
78 |
try {
|
79 |
f1 = RasterDataset.open(null, path1);
|
80 |
f2 = RasterDataset.open(null, path2);
|
81 |
} catch (NotSupportedExtensionException e) {
|
82 |
e.printStackTrace(); |
83 |
} catch (RasterDriverException e) {
|
84 |
e.printStackTrace(); |
85 |
} |
86 |
stats1 = f1.getStatistics(); |
87 |
stats2 = f2.getStatistics(); |
88 |
} |
89 |
|
90 |
public void testStack(){ |
91 |
try {
|
92 |
stats1.calcFullStatistics(); |
93 |
} catch (FileNotOpenException e) {
|
94 |
e.printStackTrace(); |
95 |
} catch (RasterDriverException e) {
|
96 |
e.printStackTrace(); |
97 |
} |
98 |
dataTestB1(stats1); |
99 |
dataTestB2(stats1); |
100 |
dataTestB3(stats1); |
101 |
//print(stats1);
|
102 |
try {
|
103 |
stats2.calcFullStatistics(); |
104 |
} catch (FileNotOpenException e) {
|
105 |
e.printStackTrace(); |
106 |
} catch (RasterDriverException e) {
|
107 |
e.printStackTrace(); |
108 |
} |
109 |
dataTestB1_2(stats2); |
110 |
dataTestB2_2(stats2); |
111 |
dataTestB3_2(stats2); |
112 |
//print(stats2);
|
113 |
} |
114 |
|
115 |
private void dataTestB1(DatasetStatistics stats){ |
116 |
assertEquals(new Double(stats.getMax()[0]), new Double(255.0)); |
117 |
assertEquals(new Double(stats.getMin()[0]), new Double(0.0)); |
118 |
assertEquals(new Double(stats.getSecondMax()[0]), new Double(254.0)); |
119 |
assertEquals(new Double(stats.getSecondMin()[0]), new Double(1.0)); |
120 |
assertEquals((int)stats.getMean()[0], 109); |
121 |
assertEquals((int)stats.getVariance()[0], 6125); |
122 |
} |
123 |
|
124 |
private void dataTestB2(DatasetStatistics stats){ |
125 |
assertEquals(new Double(stats.getMax()[1]), new Double(255.0)); |
126 |
assertEquals(new Double(stats.getMin()[1]), new Double(0.0)); |
127 |
assertEquals(new Double(stats.getSecondMax()[1]), new Double(254.0)); |
128 |
assertEquals(new Double(stats.getSecondMin()[1]), new Double(1.0)); |
129 |
assertEquals((int)stats.getMean()[1], 111); |
130 |
assertEquals((int)stats.getVariance()[1], 5722); |
131 |
} |
132 |
|
133 |
private void dataTestB3(DatasetStatistics stats){ |
134 |
assertEquals(new Double(stats.getMax()[2]), new Double(255.0)); |
135 |
assertEquals(new Double(stats.getMin()[2]), new Double(0.0)); |
136 |
assertEquals(new Double(stats.getSecondMax()[2]), new Double(254.0)); |
137 |
assertEquals(new Double(stats.getSecondMin()[2]), new Double(1.0)); |
138 |
assertEquals((int)stats.getMean()[2], 98); |
139 |
assertEquals((int)stats.getVariance()[2], 5495); |
140 |
} |
141 |
|
142 |
private void dataTestB1_2(DatasetStatistics stats){ |
143 |
assertEquals(new Double(stats.getMax()[0]), new Double(1269.0)); |
144 |
assertEquals(new Double(stats.getMin()[0]), new Double(0.0)); |
145 |
assertEquals(new Double(stats.getSecondMax()[0]), new Double(1235.0)); |
146 |
assertEquals(new Double(stats.getSecondMin()[0]), new Double(6.0)); |
147 |
assertEquals((int)stats.getMean()[0], 71); |
148 |
assertEquals((int)stats.getVariance()[0], 22678); |
149 |
} |
150 |
|
151 |
private void dataTestB2_2(DatasetStatistics stats){ |
152 |
assertEquals(new Double(stats.getMax()[1]), new Double(1525.0)); |
153 |
assertEquals(new Double(stats.getMin()[1]), new Double(0.0)); |
154 |
assertEquals(new Double(stats.getSecondMax()[1]), new Double(1522.0)); |
155 |
assertEquals(new Double(stats.getSecondMin()[1]), new Double(14.0)); |
156 |
assertEquals((int)stats.getMean()[1], 104); |
157 |
assertEquals((int)stats.getVariance()[1], 37907); |
158 |
} |
159 |
|
160 |
private void dataTestB3_2(DatasetStatistics stats){ |
161 |
assertEquals(new Double(stats.getMax()[2]), new Double(888.0)); |
162 |
assertEquals(new Double(stats.getMin()[2]), new Double(0.0)); |
163 |
assertEquals(new Double(stats.getSecondMax()[2]), new Double(884.0)); |
164 |
assertEquals(new Double(stats.getSecondMin()[2]), new Double(13.0)); |
165 |
assertEquals((int)stats.getMean()[2], 75); |
166 |
assertEquals((int)stats.getVariance()[2], 17437); |
167 |
} |
168 |
|
169 |
private void print(DatasetStatistics stats){ |
170 |
for(int iBand = 0; iBand < f1.getBandCount(); iBand ++){ |
171 |
System.out.println("Band " + iBand); |
172 |
System.out.println("...Max: " + stats.getMax()[iBand]); |
173 |
System.out.println("...Min: " + stats.getMin()[iBand]); |
174 |
System.out.println("...SecondMax: " + stats.getSecondMax()[iBand]); |
175 |
System.out.println("...SecondMin: " + stats.getSecondMin()[iBand]); |
176 |
System.out.println("...Mean: " + stats.getMean()[iBand]); |
177 |
System.out.println("...Variance: " + stats.getVariance()[iBand]); |
178 |
} |
179 |
} |
180 |
|
181 |
} |