svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src-test / org / gvsig / remotesensing / processtest / TClassificationProcessTest.java @ 21770
History | View | Annotate | Download (6.33 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 java.util.ArrayList; |
44 |
|
45 |
import junit.framework.TestCase; |
46 |
|
47 |
import org.gvsig.fmap.raster.grid.roi.VectorialROI; |
48 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
49 |
import org.gvsig.raster.RasterLibrary; |
50 |
import org.gvsig.raster.buffer.BufferFactory; |
51 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
52 |
import org.gvsig.raster.dataset.IBuffer; |
53 |
import org.gvsig.raster.grid.Grid; |
54 |
import org.gvsig.raster.grid.GridException; |
55 |
import org.gvsig.remotesensing.classification.ClassificationMaximumLikelihoodProcess; |
56 |
import org.gvsig.remotesensing.classification.ClassificationMinimumDistanceProcess; |
57 |
|
58 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
59 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
60 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
61 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
62 |
|
63 |
|
64 |
/**
|
65 |
* Este test prueba el proceso de clasificaci?n de una imagen de 4x4 con
|
66 |
* tres bandas.El proceso de clasificaci?n se realiza por minima distancia, maxima probabilidad
|
67 |
* y paralelepipedos. Los resultados se comparan con el resultado te?rico v?lido
|
68 |
*
|
69 |
* ** @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
|
70 |
* */
|
71 |
public class TClassificationProcessTest extends TestCase { |
72 |
|
73 |
private String baseDir = "./test-images/"; |
74 |
private String path1 = baseDir + "classification_image_test.tif"; |
75 |
private FLyrRasterSE lyr=null; |
76 |
private Grid dataGrid= null; |
77 |
GeneralPathX path, path2 = null;
|
78 |
IGeometry geometry, geometry2 = null;
|
79 |
|
80 |
static{
|
81 |
RasterLibrary.wakeUp(); |
82 |
} |
83 |
|
84 |
public void start() { |
85 |
this.setUp();
|
86 |
this.testStack();
|
87 |
} |
88 |
|
89 |
public void setUp() { |
90 |
System.err.println("TClassificationProcessTest running..."); |
91 |
try {
|
92 |
lyr = FLyrRasterSE.createLayer( |
93 |
path1, |
94 |
path1, |
95 |
null
|
96 |
); |
97 |
BufferFactory ds1 = new BufferFactory(lyr.getDataSource());
|
98 |
dataGrid= new Grid(ds1);
|
99 |
} catch (LoadLayerException e) {
|
100 |
System.out.print("Error en la construcci?n de la capa"); |
101 |
} catch (RasterBufferInvalidException e) {
|
102 |
System.out.print("Error en la carga del grid de datos"); |
103 |
} |
104 |
} |
105 |
|
106 |
public void testStack() { |
107 |
|
108 |
// Definici?n de las clases (rois) para el proceso
|
109 |
VectorialROI class1= new VectorialROI(dataGrid);
|
110 |
VectorialROI class2= new VectorialROI(dataGrid);
|
111 |
path = new GeneralPathX();
|
112 |
path2= new GeneralPathX();
|
113 |
|
114 |
// class1-- Roi con los pixeles 1 y 2 de la primera fila de la imagen
|
115 |
path.moveTo(dataGrid.getGridExtent().getULX(),dataGrid.getGridExtent().getULY()); |
116 |
path.lineTo(dataGrid.getGridExtent().getULX()+(2*dataGrid.getCellSize())-0.3,dataGrid.getGridExtent().getULY()); |
117 |
path.lineTo(dataGrid.getGridExtent().getULX()+(2*dataGrid.getCellSize())-0.3,dataGrid.getGridExtent().getULY()-dataGrid.getCellSize()+0.3); |
118 |
path.lineTo(dataGrid.getGridExtent().getULX(),dataGrid.getGridExtent().getULY()-dataGrid.getCellSize()+0.3);
|
119 |
path.closePath(); |
120 |
geometry=ShapeFactory.createPolygon2D(path); |
121 |
class1.addGeometry(geometry); |
122 |
|
123 |
|
124 |
//class2-- Roi con los pixeles 3 y 4 de la ultima fila
|
125 |
path2.moveTo(dataGrid.getGridExtent().getLRX(),dataGrid.getGridExtent().getLRY()); |
126 |
path2.lineTo(dataGrid.getGridExtent().getLRX(),dataGrid.getGridExtent().getLRY()+dataGrid.getCellSize()-0.1);
|
127 |
path2.lineTo(dataGrid.getGridExtent().getLRX()-(2*dataGrid.getCellSize())+0.1,dataGrid.getGridExtent().getLRY()+dataGrid.getCellSize()-0.1); |
128 |
path2.lineTo(dataGrid.getGridExtent().getLRX()-(2*dataGrid.getCellSize())+0.1,dataGrid.getGridExtent().getLRY()); |
129 |
|
130 |
geometry2=ShapeFactory.createPolygon2D(path2); |
131 |
class2.addGeometry(geometry2); |
132 |
|
133 |
ArrayList listRois=new ArrayList(); |
134 |
listRois.add(class1); |
135 |
listRois.add(class2); |
136 |
|
137 |
// Clasificacion por el m?todo de m?nima distancia
|
138 |
ClassificationMinimumDistanceProcess proceso = new ClassificationMinimumDistanceProcess();
|
139 |
proceso.addParam("layer",lyr);
|
140 |
proceso.addParam("bandList",new int[]{0,1,2}); |
141 |
proceso.addParam("rois",listRois);
|
142 |
proceso.run(); |
143 |
|
144 |
IBuffer result= (IBuffer) proceso.getResult(); |
145 |
|
146 |
assertEquals(result.getBandCount(),1);
|
147 |
|
148 |
//Comparaci?n de valores
|
149 |
assertEquals(result.getElemByte(0, 0,0),1); |
150 |
assertEquals(result.getElemByte(0, 1,0),0); |
151 |
assertEquals(result.getElemByte(0, 2,0),0); |
152 |
assertEquals(result.getElemByte(0, 3,0),0); |
153 |
|
154 |
assertEquals(result.getElemByte(1, 0,0),1); |
155 |
assertEquals(result.getElemByte(1, 1,0),1); |
156 |
assertEquals(result.getElemByte(1, 2,0),1); |
157 |
assertEquals(result.getElemByte(1, 3,0),0); |
158 |
|
159 |
assertEquals(result.getElemByte(2, 0,0),1); |
160 |
assertEquals(result.getElemByte(2, 1,0),1); |
161 |
assertEquals(result.getElemByte(2, 2,0),1); |
162 |
assertEquals(result.getElemByte(2, 3,0),0); |
163 |
|
164 |
assertEquals(result.getElemByte(3, 0,0),0); |
165 |
assertEquals(result.getElemByte(3, 1,0),1); |
166 |
assertEquals(result.getElemByte(3, 2,0),1); |
167 |
assertEquals(result.getElemByte(3, 3,0),1); |
168 |
|
169 |
|
170 |
// Clasificacion por el m?todo de m?nima distancia
|
171 |
ClassificationMaximumLikelihoodProcess proceso2 = new ClassificationMaximumLikelihoodProcess();
|
172 |
proceso2.addParam("layer",lyr);
|
173 |
proceso2.addParam("bandList",new int[]{0,1,2}); |
174 |
proceso2.addParam("rois",listRois);
|
175 |
proceso2.run(); |
176 |
|
177 |
result= (IBuffer) proceso2.getResult(); |
178 |
System.out.print("Proceso Completado.."); |
179 |
|
180 |
} |
181 |
|
182 |
} |