Statistics
| Revision:

root / trunk / extensions / extRemoteSensing / src-test / org / gvsig / remotesensing / processtest / TPCStatisticProcess.java @ 21661

History | View | Annotate | Download (4.37 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.io.File;
44

    
45
import junit.framework.TestCase;
46

    
47
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
48
import org.gvsig.raster.RasterLibrary;
49
import org.gvsig.remotesensing.principalcomponents.PCStatisticsProcess;
50

    
51
import Jama.Matrix;
52

    
53
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
54

    
55

    
56
/**
57
* Este test prueba el proceso de calculo de las matriz de autovectores de la 
58
* imagen "PCA_bouldr_tm_int16.img", de seis bandas.
59
* Los elementos de la matriz obtenida en el proceso se comparan en valor absoluto
60
* comparan con los elementos de la matriz de autovalores proporcionada por ERDAS.
61
* 
62
* ** @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
63
* */
64

    
65
public class TPCStatisticProcess extends TestCase {
66

    
67
        private String baseDir = "./test-images/";
68
        private String path1 = baseDir + "bouldr_tm_Int16.dat";
69

    
70
        static{
71
                RasterLibrary.wakeUp();        
72
        }
73
        
74
        public void start() {
75
                this.setUp();
76
                this.testStack();
77
        }
78
        
79
        public void setUp() {
80
                System.err.println("TPCStatisticProcess running...");
81
        }
82
        
83
        public void testStack() {
84
        
85
                // Matriz de autovectores obtenida con ERDAS
86
                double autoVectorMatrixERDAS[][] = {
87
                                {0.4467930765462516 ,-0.2132448427522436, 0.61999384198935, 0.5583203571234574 ,0.1212877203683758 ,0.2099473443357927 },
88
                                {0.2302721175129133 ,-0.06284659594556273, 0.2921484644686843 ,-0.1714351492532642, -0.09649740387440189 ,-0.9049710341330732},
89
                                {0.287184731205834, 0.07705684070022263, 0.3977736576013743, -0.7037344497503186, -0.351412521922381 ,0.3669200927798035},
90
                                {0.3884643668946926, -0.7858370140117444 ,-0.408108215862561 ,-0.2060071443748747 ,0.1431802274591002, 0.04542891295109729},
91
                                {0.6376828181240171, 0.4126887053417631, -0.451856773747645, 0.2418214698550539, -0.4001988234001318, -0.01540747915579309},
92
                                {0.3276151521697355 ,0.3959638943275853 ,-0.0361409474886444, -0.2504588305907446 ,0.8196505984901843 ,0.004243695755382132}                
93
                };
94
                
95

    
96
                FLyrRasterSE lyr = null;
97
                int endIndex = path1.lastIndexOf(".");
98
                if (endIndex < 0)
99
                        endIndex = path1.length();
100
                try {
101
                        lyr = FLyrRasterSE.createLayer(
102
                                        path1.substring(path1.lastIndexOf(File.separator) + 1, endIndex),
103
                                        path1,
104
                                null
105
                                        );
106
                } catch (LoadLayerException e) {
107
                        System.out.print("Error en la construcci?n de la capa");
108
                }
109

    
110
                
111
                PCStatisticsProcess sProcess= new PCStatisticsProcess();
112
                sProcess.addParam("selectedBands",new boolean[]{true,true,true,true,true,true});
113
                sProcess.addParam("layer",lyr);
114
                sProcess.run();
115
                
116
                Matrix autoV=sProcess.getAutoVectorMatrix();
117
                // Reordenamos en orden descencente del valor de los autovectores
118
                int resultOrden[]= new int[autoV.getRowDimension()];
119
                int cont = autoV.getRowDimension()-1;
120
                for(int i=0;i<autoV.getRowDimension();i++){
121
                                        resultOrden[i]=cont;
122
                                        cont--;
123
                }
124
                
125
                /** La comparacion se realiza en valor absoluto, ya que el criterio de signos 
126
                 *  puede variar */
127
                
128
                for(int i=0; i<autoVectorMatrixERDAS.length;i++)
129
                        for(int j=0;j<autoVectorMatrixERDAS[0].length;j++)
130
                        {        
131
                                assertEquals(java.lang.Math.abs(autoVectorMatrixERDAS[i][j]), java.lang.Math.abs(autoV.get(i, resultOrden[j])), 0.005);
132
                        }
133
        }
134
}