root / trunk / extensions / extRemoteSensing / src-test / org / gvsig / remotesensing / processtest / TTasseledCapProcess.java @ 21678
History | View | Annotate | Download (6.08 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program 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 General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Iba?ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.processtest; |
42 |
|
43 |
import junit.framework.TestCase; |
44 |
|
45 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
46 |
import org.gvsig.raster.RasterLibrary; |
47 |
import org.gvsig.raster.buffer.BufferFactory; |
48 |
import org.gvsig.raster.buffer.RasterBufferInvalidAccessException; |
49 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
50 |
import org.gvsig.raster.dataset.IBuffer; |
51 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
52 |
import org.gvsig.raster.dataset.RasterDataset; |
53 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
54 |
import org.gvsig.raster.grid.Grid; |
55 |
import org.gvsig.remotesensing.tasseledcap.TasseledCapProcess; |
56 |
|
57 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
58 |
|
59 |
|
60 |
/**
|
61 |
* Este test prueba el proceso de calculo de la trasformacion Tasseled Cap.
|
62 |
* A partir del fichero "bhtmref.img", se construye un grid con las bandas correspondientes
|
63 |
* (las 6 bandas de la imagen para el caso de LandSat TM y ETM y las 4 primeras bandas para el caso de MSS).
|
64 |
* Construido el grid se lanza el calculo y se comparan los resultados con los ficheros que se
|
65 |
* detallan a continuaci?n calculados previamente con Envi.
|
66 |
* Para el caso de la Imagen LandSat TM, se compara el resultado con Imagen: LandSatTM_Envi
|
67 |
* Para el caso de la Imagen LandSat ETM, se compara el resultado con Imagen LandSatETM_Envi
|
68 |
* Para el caso de la Imagen LandSat MSS, se compara el resultado con Imagen LandSatMSS_Envi.tif
|
69 |
*
|
70 |
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
|
71 |
* */
|
72 |
|
73 |
public class TTasseledCapProcess extends TestCase { |
74 |
|
75 |
private String baseDir = "./test-images/"; |
76 |
private String path1 = baseDir + "bhtmref.img"; |
77 |
private String path2 = baseDir + "LandSatTM_Envi"; |
78 |
private String path3 = baseDir + "LandSatETM_Envi"; |
79 |
private String path4 = baseDir + "LandSatMSS_Envi.tif"; |
80 |
private RasterDataset f2,f3,f4 = null; |
81 |
private BufferFactory ds2,ds3,ds4 = null; |
82 |
private FLyrRasterSE lyr1 = null; |
83 |
|
84 |
static{
|
85 |
RasterLibrary.wakeUp(); |
86 |
} |
87 |
|
88 |
public void start() { |
89 |
this.setUp();
|
90 |
this.testStack();
|
91 |
} |
92 |
|
93 |
public void setUp() { |
94 |
System.err.println("TTasseledCapProcess running..."); |
95 |
|
96 |
try {
|
97 |
lyr1 = FLyrRasterSE.createLayer( |
98 |
path1, |
99 |
path1, |
100 |
null
|
101 |
); |
102 |
} catch (LoadLayerException e) {
|
103 |
System.out.print("Error en la construcci?n de la capa"); |
104 |
} |
105 |
|
106 |
try {
|
107 |
f2= RasterDataset.open(null,path2);
|
108 |
f3 = RasterDataset.open(null,path3);
|
109 |
f4= RasterDataset.open(null, path4);
|
110 |
} catch (NotSupportedExtensionException e) {
|
111 |
e.printStackTrace(); |
112 |
} catch (RasterDriverException e) {
|
113 |
// TODO Auto-generated catch block
|
114 |
e.printStackTrace(); |
115 |
} |
116 |
ds2= new BufferFactory (f2);
|
117 |
ds3= new BufferFactory (f3);
|
118 |
ds4= new BufferFactory (f4);
|
119 |
|
120 |
} |
121 |
|
122 |
public void testStack() { |
123 |
|
124 |
Grid enviResultTM=null;
|
125 |
Grid enviResultETM=null;
|
126 |
Grid enviResultMSS=null;
|
127 |
|
128 |
try {
|
129 |
enviResultTM= new Grid(ds2);
|
130 |
enviResultETM= new Grid(ds3);
|
131 |
enviResultMSS= new Grid (ds4);
|
132 |
|
133 |
} catch (RasterBufferInvalidException e) {
|
134 |
e.printStackTrace(); |
135 |
} |
136 |
|
137 |
|
138 |
// **Caso LandSat MSS
|
139 |
TasseledCapProcess mssProcess= new TasseledCapProcess();
|
140 |
mssProcess.addParam("bands", new int[]{0,1,2,3}); |
141 |
mssProcess.addParam("layer",lyr1);
|
142 |
mssProcess.addParam("type",new Integer(0)); |
143 |
mssProcess.run(); |
144 |
try {
|
145 |
compare(mssProcess.getBufferResult(),enviResultMSS.getRasterBuf()); |
146 |
} catch (RasterBufferInvalidAccessException e) {
|
147 |
e.printStackTrace(); |
148 |
} |
149 |
|
150 |
|
151 |
|
152 |
//**Caso LandSat TM
|
153 |
TasseledCapProcess tmProcess= new TasseledCapProcess();
|
154 |
tmProcess.addParam("bands", new int[]{0,1,2,3,4,5}); |
155 |
tmProcess.addParam("layer",lyr1);
|
156 |
tmProcess.addParam("type",new Integer(1)); |
157 |
tmProcess.run(); |
158 |
try {
|
159 |
compare(tmProcess.getBufferResult(),enviResultTM.getRasterBuf()); |
160 |
} catch (RasterBufferInvalidAccessException e) {
|
161 |
e.printStackTrace(); |
162 |
} |
163 |
|
164 |
|
165 |
//**Caso LandSat ETM
|
166 |
TasseledCapProcess etmProcess= new TasseledCapProcess();
|
167 |
etmProcess.addParam("bands", new int[]{0,1,2,3,4,5}); |
168 |
etmProcess.addParam("layer",lyr1);
|
169 |
etmProcess.addParam("type",new Integer(2)); |
170 |
etmProcess.run(); |
171 |
try {
|
172 |
compare(etmProcess.getBufferResult(),enviResultETM.getRasterBuf()); |
173 |
} catch (RasterBufferInvalidAccessException e) {
|
174 |
e.printStackTrace(); |
175 |
} |
176 |
|
177 |
|
178 |
} |
179 |
|
180 |
//**Metodo que compara celda a celda cada uno de los valores de dos grids.
|
181 |
// Para imagenes LandSat ETM, la sexta banda no se compara porque envi realiza una transformacion
|
182 |
// para evitar los numeros negativos *//*
|
183 |
private void compare(IBuffer buffer, IBuffer buffer2) throws RasterBufferInvalidAccessException { |
184 |
assertEquals(buffer.getBandCount(),buffer2.getBandCount()); |
185 |
for(int band=0; band<buffer.getBandCount();band++){ |
186 |
if(band<5){ |
187 |
for(int line = 0; line < buffer2.getHeight(); line++){ |
188 |
for(int col = 0; col < buffer2.getWidth(); col++){ |
189 |
assertEquals(buffer2.getElemFloat(col,line,band), buffer.getElemFloat(col, line,band),0.1);
|
190 |
} |
191 |
} |
192 |
} |
193 |
|
194 |
} |
195 |
} |
196 |
} |