Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / LinearEnhancementFilter.java @ 11396

History | View | Annotate | Download (4.88 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 IVER T.I. 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
package org.gvsig.raster.grid.filter.enhancement;
20

    
21
import org.gvsig.raster.buffer.RasterBuffer;
22
import org.gvsig.raster.dataset.IBuffer;
23
import org.gvsig.raster.dataset.properties.DatasetListStatistics;
24
import org.gvsig.raster.grid.filter.RasterFilter;
25

    
26

    
27
/**
28
 * Clase base para los filtros de realzado lineal. Lee el m?nimo y m?xmo de la clase
29
 * Statistic que ser?n calculados por PercentTailTrimFilter o ComputeMinMaxFilter dependiendo
30
 * de si est? activado el recorte de colas o no. En Statistic tambi?n est?n los segundos
31
 * valores despu?s del m?nimo y m?ximo que son los que se utilizan con la opci?n eliminar
32
 * extremos activada. Estos se usaran en vez del m?nimo y m?ximo cuando la variable
33
 * removeExtrema est? a true.
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 */
36
public abstract class LinearEnhancementFilter extends RasterFilter {
37
        public static String                        genericName = "enhanced";
38
        
39
    protected double[]                         scale = new double[3];
40
    protected double[]                         offset = new double[3];
41
    protected DatasetListStatistics        stats = null; 
42
    
43
    protected double[]                         minBandValue = null;
44
    protected double[]                         maxBandValue = null;
45
    
46
    protected boolean                                 removeEnds = false;
47
    protected double                                 tailTrim = 0D;
48
    protected IBuffer                                rasterResult = null;
49
        protected int                                         nbands = 3;
50

    
51
    /**
52
     * Constructor
53
     *
54
     */
55
    public LinearEnhancementFilter() {
56
        super();
57
        super.fName = genericName;
58
        this.fPriority = 21;
59
    }
60

    
61
    /* (non-Javadoc)
62
     * @see org.cresques.io.raster.IRasterFilter#pre()
63
     */
64
    public void pre() {
65
        raster = (IBuffer) params.get("raster");
66
        stats = (DatasetListStatistics) params.get("stats");
67
        removeEnds = ((Boolean) params.get("remove")).booleanValue();
68
        tailTrim = ((Double) params.get("tailTrim")).doubleValue();
69
        height = raster.getHeight();
70
        width = raster.getWidth();
71
        
72
        if(tailTrim != 0){ //Max y Min con recorte de colas
73
                double[][] tailTrimByBand = (double[][])stats.getTailTrimValue(tailTrim);
74
                scale = new double[tailTrimByBand.length];
75
            offset = new double[tailTrimByBand.length];
76
                minBandValue = new double[tailTrimByBand.length];
77
                maxBandValue = new double[tailTrimByBand.length];
78
                for(int i = 0; i < tailTrimByBand.length; i++){
79
                        minBandValue[i] = tailTrimByBand[i][0];
80
                        maxBandValue[i] = tailTrimByBand[i][1];
81
                }
82
        }else{
83
                scale = new double[stats.getMin().length];
84
            offset = new double[stats.getMin().length];
85
                    if (removeEnds) { //Si est? activado eliminar extremos gastamos el 2? m?ximo/m?nimo
86
                            minBandValue = stats.getSecondMin();
87
                    maxBandValue = stats.getSecondMax();
88
                } else { //Si no est? activado eliminar extremos
89
                        minBandValue = stats.getMin();
90
                    maxBandValue = stats.getMax();
91
                }
92
        }
93

    
94
        for (int i = 0; i < minBandValue.length; i++) {
95
            scale[i] = 255D / (maxBandValue[i] - minBandValue[i]);
96
            offset[i] = (255D * minBandValue[i]) / (minBandValue[i] -
97
                        maxBandValue[i]);
98
        }
99
        
100
        nbands = stats.getBandCount();
101
        rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
102
    }
103

    
104
    /**
105
     * Obtiene true si est? activado el flag de eliminar extremos y false si no lo est?
106
     */
107
    public Boolean getRemoveEnds() {
108
        return new Boolean(removeEnds);
109
    }
110
    
111
    /**
112
     * Obtiene el porcentaje de recorte de colas aplicado o 0 si no tiene.
113
     * @return 
114
     */
115
    public Double getTailTrim(){
116
            return new Double(tailTrim);
117
    }
118
    
119
    /*
120
     *  (non-Javadoc)
121
     * @see org.gvsig.fmap.grid.filter.IRasterFilter#getOutRasterDataType()
122
     */
123
    public int getOutRasterDataType() {
124
                return IBuffer.TYPE_BYTE;
125
        }
126
    
127
    /*
128
         *  (non-Javadoc)
129
         * @see org.gvsig.fmap.grid.filter.IRasterFilter#getResult(java.lang.String)
130
         */
131
        public Object getResult(String name) {
132
        return (Object) this.rasterResult;
133
        }
134
}