Statistics
| Revision:

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

History | View | Annotate | Download (6.18 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.Params;
24
import org.gvsig.raster.dataset.properties.DatasetListStatistics;
25
import org.gvsig.raster.grid.filter.RasterFilter;
26
/**
27
 * Clase base para los filtros de realzado lineal. Lee el m?nimo y m?xmo de la
28
 * clase Statistic que ser?n calculados por PercentTailTrimFilter o
29
 * ComputeMinMaxFilter dependiendo de si est? activado el recorte de colas o no.
30
 * En Statistic tambi?n est?n los segundos valores despu?s del m?nimo y m?ximo
31
 * que son los que se utilizan con la opci?n eliminar extremos activada. Estos
32
 * se usaran en vez del m?nimo y m?ximo cuando la variable removeExtrema est? a
33
 * true.
34
 *
35
 * @version 31/05/2007
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class LinearEnhancementFilter extends RasterFilter {
39
        protected double[]                 scale = new double[3];
40
        protected double[]                 offset = new double[3];
41
        protected DatasetListStatistics           stats = null;
42
        protected double[]                 minBandValue        = null;
43
        protected double[]                 maxBandValue        = null;
44
        protected boolean                  removeEnds = false;
45
        protected double                   tailTrim        = 0D;
46
        protected IBuffer                  rasterResult        = null;
47
        protected int                      nbands = 3;
48
        protected int[]                    renderBands = null;
49
        public static String[]             names = new String[] {"enhanced"};
50

    
51
        /**
52
         * Construye un LinearEnhancementFilter
53
         */
54
        public LinearEnhancementFilter() {
55
                setName(names[0]);
56
        }
57

    
58
        /*
59
         * (non-Javadoc)
60
         * @see org.gvsig.raster.grid.filter.RasterFilter#pre()
61
         */
62
        public void pre() {
63
                raster = (IBuffer) params.get("raster");
64
                stats = (DatasetListStatistics) params.get("stats");
65
                removeEnds = ((Boolean) params.get("remove")).booleanValue();
66
                tailTrim = ((Double) params.get("tailTrim")).doubleValue();
67
                renderBands = (int[]) params.get("renderBands");
68
                height = raster.getHeight();
69
                width = raster.getWidth();
70

    
71
                double[][] tailTrimByBand = (double[][]) stats.getTailTrimValue(tailTrim);
72
                if ((tailTrim != 0) && (tailTrimByBand != null)) { // Max y Min con recorte de colas
73

    
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] - maxBandValue[i]);
97
                }
98

    
99
                nbands = stats.getBandCount();
100
                rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
101
        }
102

    
103
        /**
104
         * Obtiene true si est? activado el flag de eliminar extremos y false si no lo
105
         * 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.raster.grid.filter.RasterFilter#getOutRasterDataType()
122
         */
123
        public int getOutRasterDataType() {
124
                return IBuffer.TYPE_BYTE;
125
        }
126

    
127
        /*
128
         * (non-Javadoc)
129
         * @see org.gvsig.raster.grid.filter.RasterFilter#getResult(java.lang.String)
130
         */
131
        public Object getResult(String name) {
132
                if (name.equals("raster"))
133
                        return (Object) this.rasterResult;
134
                return null;
135
        }
136

    
137
        /*
138
         * (non-Javadoc)
139
         * @see org.gvsig.raster.grid.filter.RasterFilter#getGroup()
140
         */
141
        public String getGroup() {
142
                return "basics";
143
        }
144

    
145
        /*
146
         * (non-Javadoc)
147
         * @see org.gvsig.raster.grid.filter.RasterFilter#getUIParams()
148
         */
149
        public Params getUIParams(String nameFilter) {
150
                Params params = new Params();
151
                params.setParam("RemoveEnds",
152
                                removeEnds + "",
153
                                Params.CHECK,
154
                                null);
155
                params.setParam("TailTrim",
156
                                Math.round(tailTrim*100.0) + "",
157
                                Params.SLIDER,
158
                                new String[]{ "0", "100", "0", "1", "25" }); //min, max, valor defecto, intervalo peque?o, intervalo grande;
159
                return params;
160
        }
161

    
162
        /*
163
         * (non-Javadoc)
164
         * @see org.gvsig.raster.grid.filter.RasterFilter#post()
165
         */
166
        public void post() {
167
                // En caso de que nadie apunte a raster, se liberar? su memoria.
168
                raster = null;
169
        }
170

    
171
        /*
172
         * (non-Javadoc)
173
         * @see org.gvsig.raster.grid.filter.RasterFilter#getInRasterDataType()
174
         */
175
        public int getInRasterDataType() {
176
                return 0;
177
        }
178

    
179
        /*
180
         * (non-Javadoc)
181
         * @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
182
         */
183
        public void process(int x, int y) {
184
        }
185

    
186
        /*
187
         * (non-Javadoc)
188
         * @see org.gvsig.raster.grid.filter.RasterFilter#getNames()
189
         */
190
        public String[] getNames() {
191
                return names;
192
        }
193
        
194
        /*
195
         * (non-Javadoc)
196
         * @see org.gvsig.raster.grid.filter.RasterFilter#isVisible()
197
         */
198
        public boolean isVisible() {
199
                return false;
200
        }
201
}