Statistics
| Revision:

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

History | View | Annotate | Download (3.4 KB)

1
package org.gvsig.remotesensing.processtest;
2

    
3
import junit.framework.TestCase;
4

    
5
import org.gvsig.raster.RasterLibrary;
6
import org.gvsig.raster.buffer.BufferFactory;
7
import org.gvsig.raster.buffer.RasterBufferInvalidAccessException;
8
import org.gvsig.raster.buffer.RasterBufferInvalidException;
9
import org.gvsig.raster.dataset.NotSupportedExtensionException;
10
import org.gvsig.raster.dataset.RasterDataset;
11
import org.gvsig.raster.dataset.RasterDriverException;
12
import org.gvsig.raster.grid.Grid;
13
import org.gvsig.remotesensing.principalcomponents.PCImageProcess;
14
import org.gvsig.remotesensing.principalcomponents.PCStatisticsProcess;
15

    
16
import Jama.Matrix;
17

    
18

    
19
/**
20
* Este test prueba el proceso de calculo de las matriz de autovectores de la 
21
* imagen "PCA_bouldr_tm_int16.img", de seis bandas.
22
* Los elementos de la matriz obtenida en el proceso se comparan en valor absoluto
23
* comparan con los elementos de la matriz de autovalores proporcionada por ERDAS.
24
* ** @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
25
* */
26

    
27
public class TPCStatisticProcess extends TestCase {
28

    
29
        private String baseDir = "./test-images/";
30
        private String path1 = baseDir + "bouldr_tm_Int16.dat";
31
        private RasterDataset f1 = null;
32
        private BufferFactory ds1 = null;
33

    
34
        
35
        static{
36
                RasterLibrary.wakeUp();        
37
        }
38
        
39
        public void start() {
40
                this.setUp();
41
                this.testStack();
42
        }
43
        
44
        public void setUp() {
45
                System.err.println("TPCStatisticProcess running...");
46
                try {
47
                        f1 = RasterDataset.open(null, path1);
48
                } catch (NotSupportedExtensionException e) {
49
                        e.printStackTrace();
50
                } catch (RasterDriverException e) {
51
                        e.printStackTrace();
52
                }
53
                ds1 = new BufferFactory(f1);
54
        
55
        }
56
        
57
        public void testStack() {
58
        
59
                // Matriz de autovectores obtenida con ERDAS
60
                double autoVectorMatrixERDAS[][] = {
61
                                {0.4467930765462516 ,-0.2132448427522436, 0.61999384198935, 0.5583203571234574 ,0.1212877203683758 ,0.2099473443357927 },
62
                                {0.2302721175129133 ,-0.06284659594556273, 0.2921484644686843 ,-0.1714351492532642, -0.09649740387440189 ,-0.9049710341330732},
63
                                {0.287184731205834, 0.07705684070022263, 0.3977736576013743, -0.7037344497503186, -0.351412521922381 ,0.3669200927798035},
64
                                {0.3884643668946926, -0.7858370140117444 ,-0.408108215862561 ,-0.2060071443748747 ,0.1431802274591002, 0.04542891295109729},
65
                                {0.6376828181240171, 0.4126887053417631, -0.451856773747645, 0.2418214698550539, -0.4001988234001318, -0.01540747915579309},
66
                                {0.3276151521697355 ,0.3959638943275853 ,-0.0361409474886444, -0.2504588305907446 ,0.8196505984901843 ,0.004243695755382132}                
67
                };
68
                
69
                Grid g=null;
70
                try {
71
                         g = new Grid(ds1);
72
                } catch (RasterBufferInvalidException e) {
73
                        e.printStackTrace();
74
                }
75
        
76
                PCStatisticsProcess sProcess= new PCStatisticsProcess(ds1.getDataSource(),null,new boolean[]{true,true,true,true,true,true});
77
                sProcess.calculate();
78
                Matrix autoV=sProcess.getAutoVectorMatrix();
79
                // Reordenamos en orden descencente del valor de los autovectores
80
                int resultOrden[]= new int[autoV.getRowDimension()];
81
                int cont = autoV.getRowDimension()-1;
82
                for(int i=0;i<autoV.getRowDimension();i++){
83
                                        resultOrden[i]=cont;
84
                                        cont--;
85
                }
86
                
87
                /**La comparacion se realiza en valor absoluto, ya que el criterio de signos puede variar*/
88
                for(int i=0; i<autoVectorMatrixERDAS.length;i++)
89
                        for(int j=0;j<autoVectorMatrixERDAS[0].length;j++)
90
                        {        
91
                                assertEquals(java.lang.Math.abs(autoVectorMatrixERDAS[i][j]), java.lang.Math.abs(autoV.get(i, resultOrden[j])), 0.005);
92
                        }
93
                
94
        }
95
        
96
        
97

    
98
                
99
}