Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src-test / org / cresques / io / datastruct / TestHistogram3bandByte.java @ 8026

History | View | Annotate | Download (3.04 KB)

1
/*
2
 * Created on 27-jul-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.cresques.io.datastruct;
26

    
27
import org.cresques.io.GeoRasterFile;
28
import org.cresques.io.data.Grid;
29

    
30
/**
31
 * Este test prueba el acceso a datos a traves de un grid
32
 * @author Nacho Brodin (brodin_ign@gva.es)
33
 *
34
 */
35
public class TestHistogram3bandByte extends Thread{
36

    
37
        private static boolean        FULL_HISTOGRAM = true;
38
        
39
        //private String                         path = "/home/imagenes/03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg";
40
        //private String                         path = "/home/imagenes/wcs16bits.tif";
41
        private String                         path = "/home/imagenes/q101866.sid";
42
        private GeoRasterFile         f1 = null;
43
        private Grid                         grid = null;
44
        private        Histogram                 hist = null;
45
        private int[][]                 histArray = null;
46
        private int                                nPixels = 0;
47
        
48
        public TestHistogram3bandByte() {
49
                System.out.println("TestHistogram3bandByte running...");
50
                f1 = GeoRasterFile.openFile(null, path);
51
                grid = new Grid(f1);
52
                hist = new Histogram(grid);        
53
                boolean[] bands = {true, true, true};
54
                if(!FULL_HISTOGRAM){
55
                        hist.setAreaOfInterest(100, 100, 10, 10);
56
                        hist.calcHistogramFromLimetedArea(bands);
57
                }else 
58
                        //Esto es igual a calcular el histograma de un area de interes de tama?o de toda la imagen
59
                        hist.calcFullHistogram(bands); 
60
                start();
61
        }
62
        
63
        public void run(){
64
                System.out.print("Calculando histograma ...");
65
                while(hist.getPercent() < 100){
66
                        System.out.print(" "+hist.getPercent());
67
                        try {
68
                                sleep(10);
69
                        } catch (InterruptedException e) {
70
                                e.printStackTrace();
71
                        }
72
                }
73
                histArray = hist.getFullHistogram();
74
                System.out.println();
75
                System.out.println("Total pixeles:" + (grid.getHeight() * grid.getWidth()));
76
                System.out.println("HISTOGRAMA:");
77
                for(int iBand = 0; iBand < histArray.length; iBand ++)
78
                        for(int i = 0; i < histArray[iBand].length; i ++){
79
                                if(i < 1500)
80
                                        System.out.println("Band:"+iBand+" "+i+"="+histArray[iBand][i]);
81
                                if(iBand == 0 && histArray[iBand][i] != 0)
82
                                        nPixels += histArray[iBand][i];
83
                        }
84
                
85
                System.out.println("N?mero de pixeles por banda:"+nPixels);
86

    
87
        }
88

    
89
        public static void main(String[] args){
90
                TestHistogram3bandByte test = new TestHistogram3bandByte();
91
        }
92
}