Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / LinearEnhancementFilter.java @ 11076

History | View | Annotate | Download (4.91 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.i18n.Messages;
22
import org.gvsig.raster.buffer.RasterBuffer;
23
import org.gvsig.raster.dataset.IBuffer;
24
import org.gvsig.raster.dataset.properties.DatasetListStatistics;
25
import org.gvsig.raster.grid.filter.RasterFilter;
26

    
27

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

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

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

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

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