Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / statistics / TailTrimByteFilter.java @ 2438

History | View | Annotate | Download (2.92 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.impl.grid.filter.statistics;
23

    
24
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
25
import org.gvsig.fmap.dal.coverage.exception.FilterAddException;
26
/**
27
 * Proceso del filtro de recorte de colas aplicado al tipo de datos byte
28
 * @version 31/05/2007
29
 * @author Nacho Brodin (nachobrodin@gmail.com)
30
 */
31
public class TailTrimByteFilter extends TailTrimFilter {
32

    
33
        /**
34
         * Array con el resultado. La primera dimensi?n es el n?mero de bandas y la segunda son dos elementos 
35
         * el m?ximo y el m?nimo para esa banda.
36
         */
37
        private double[][]        result        = null;
38

    
39
        public TailTrimByteFilter() {}
40

    
41
        /**
42
         * Obtiene par?metros para el filtro y obtiene el ancho y alto de
43
         * la imagen sobre la que se aplica el filtro
44
         * @throws FilterAddException 
45
         */
46
        public void pre() throws FilterAddException {
47
                super.pre();
48
                sample = new int[raster.getBandCount()][nSamples];
49
                result = new double[raster.getBandCount()][2];
50
        }
51

    
52
        /**
53
         * Carga sobre el vector de muestras los valores de estas cogidos
54
         * de la imagen
55
         */
56
        public void process(int col, int line) {
57
                for (int iBand = 0; iBand < raster.getBandCount(); iBand++)
58
                        sample[iBand][count] = (raster.getElemByte(line, col, iBand) & 0xff);
59
                count++;
60
        }
61

    
62
        public int getInRasterDataType() {
63
                return Buffer.TYPE_BYTE;
64
        }
65

    
66
        public int getOutRasterDataType() {
67
                return Buffer.TYPE_BYTE;
68
        }
69

    
70
        public void post() {
71
                super.post();
72

    
73
                //Cogemos el minimo y m?ximo para cada banda
74
                for (int i = 0; i < raster.getBandCount(); i++) {
75
                        result[i][0] = sample[i][posInit + tailSize];
76
                        result[i][1] = sample[i][(posInit + nSamples) - tailSize];
77
                }
78
                stats.setTailTrimValue(tailPercent, result);
79
                
80
                //Cogemos el minimo y m?ximo para cada banda
81
                for (int iValue = 0; iValue < tailSizeList.length; iValue++) {
82
                        double [][] res = new double[raster.getBandCount()][2];
83
                        for (int i = 0; i < raster.getBandCount(); i++) {
84
                                res[i][0] = sample[i][posInit + tailSizeList[iValue]];
85
                                res[i][1] = sample[i][(posInit + nSamples) - tailSizeList[iValue]];
86
                        }
87
                        stats.setTailTrimValue(tailPercentList[iValue], res);
88
                }
89
        }
90

    
91
}