svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / LinearEnhancementFilter.java @ 11864
History | View | Annotate | Download (6.19 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 |
/**
|
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 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 |
protected int[] renderBands = null; |
51 |
|
52 |
|
53 |
/**
|
54 |
* Construye un LinearEnhancementFilter
|
55 |
*/
|
56 |
public LinearEnhancementFilter() {
|
57 |
super();
|
58 |
super.fName = genericName;
|
59 |
} |
60 |
|
61 |
/*
|
62 |
* (non-Javadoc)
|
63 |
*
|
64 |
* @see org.cresques.io.raster.IRasterFilter#pre()
|
65 |
*/
|
66 |
public void pre() { |
67 |
raster = (IBuffer) params.get("raster");
|
68 |
stats = (DatasetListStatistics) params.get("stats");
|
69 |
removeEnds = ((Boolean) params.get("remove")).booleanValue(); |
70 |
tailTrim = ((Double) params.get("tailTrim")).doubleValue(); |
71 |
renderBands = (int[]) params.get("renderBands"); |
72 |
height = raster.getHeight(); |
73 |
width = raster.getWidth(); |
74 |
|
75 |
if (tailTrim != 0) { // Max y Min con recorte de colas |
76 |
double[][] tailTrimByBand = (double[][]) stats.getTailTrimValue(tailTrim); |
77 |
scale = new double[tailTrimByBand.length]; |
78 |
offset = new double[tailTrimByBand.length]; |
79 |
minBandValue = new double[tailTrimByBand.length]; |
80 |
maxBandValue = new double[tailTrimByBand.length]; |
81 |
for (int i = 0; i < tailTrimByBand.length; i++) { |
82 |
minBandValue[i] = tailTrimByBand[i][0];
|
83 |
maxBandValue[i] = tailTrimByBand[i][1];
|
84 |
} |
85 |
} else {
|
86 |
scale = new double[stats.getMin().length]; |
87 |
offset = new double[stats.getMin().length]; |
88 |
if (removeEnds) { // Si est? activado eliminar extremos gastamos el 2? |
89 |
// m?ximo/m?nimo
|
90 |
minBandValue = stats.getSecondMin(); |
91 |
maxBandValue = stats.getSecondMax(); |
92 |
} else { // Si no est? activado eliminar extremos |
93 |
minBandValue = stats.getMin(); |
94 |
maxBandValue = stats.getMax(); |
95 |
} |
96 |
} |
97 |
|
98 |
for (int i = 0; i < minBandValue.length; i++) { |
99 |
scale[i] = 255D / (maxBandValue[i] - minBandValue[i]);
|
100 |
offset[i] = (255D * minBandValue[i]) / (minBandValue[i] - maxBandValue[i]);
|
101 |
} |
102 |
|
103 |
nbands = stats.getBandCount(); |
104 |
rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Obtiene true si est? activado el flag de eliminar extremos y false si no lo
|
109 |
* est?
|
110 |
*/
|
111 |
public Boolean getRemoveEnds() { |
112 |
return new Boolean(removeEnds); |
113 |
} |
114 |
|
115 |
/**
|
116 |
* Obtiene el porcentaje de recorte de colas aplicado o 0 si no tiene.
|
117 |
*
|
118 |
* @return
|
119 |
*/
|
120 |
public Double getTailTrim(){ |
121 |
return new Double(tailTrim); |
122 |
} |
123 |
|
124 |
/*
|
125 |
* (non-Javadoc)
|
126 |
* @see org.gvsig.fmap.grid.filter.IRasterFilter#getOutRasterDataType()
|
127 |
*/
|
128 |
public int getOutRasterDataType() { |
129 |
return IBuffer.TYPE_BYTE;
|
130 |
} |
131 |
|
132 |
|
133 |
public Object getResult(String name) { |
134 |
return (Object) this.rasterResult; |
135 |
} |
136 |
|
137 |
/*
|
138 |
* (non-Javadoc)
|
139 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getName()
|
140 |
*/
|
141 |
public String getName() { |
142 |
return genericName;
|
143 |
} |
144 |
|
145 |
/*
|
146 |
* (non-Javadoc)
|
147 |
* @see org.gvsig.raster.grid.filter.IRasterFilter#getGroup()
|
148 |
*/
|
149 |
public String getGroup() { |
150 |
return "basics"; |
151 |
} |
152 |
|
153 |
/*
|
154 |
* (non-Javadoc)
|
155 |
* @see org.gvsig.raster.grid.filter.IRasterFilter#getUIParams()
|
156 |
*/
|
157 |
public Params getUIParams() {
|
158 |
Params params = new Params();
|
159 |
params.setParam("RemoveEnds",
|
160 |
removeEnds + "",
|
161 |
Params.CHECK, |
162 |
null);
|
163 |
params.setParam("TailTrim",
|
164 |
Math.round(tailTrim*100.0) + "", |
165 |
Params.SLIDER, |
166 |
new String[]{ "0", "100", "0", "1", "25" }); //min, max, valor defecto, intervalo peque?o, intervalo grande; |
167 |
return params;
|
168 |
} |
169 |
|
170 |
/*
|
171 |
* (non-Javadoc)
|
172 |
* @see org.gvsig.raster.grid.filter.RasterFilter#post()
|
173 |
*/
|
174 |
public void post() { |
175 |
if (nbands < rasterResult.getBandCount()) {
|
176 |
for (int band = nbands; band < rasterResult.getBandCount(); band++) { |
177 |
if (renderBands != null && band < renderBands.length) { |
178 |
for (int col = 0; col < rasterResult.getWidth(); col++) |
179 |
for (int row = 0; row < rasterResult.getHeight(); row++) |
180 |
rasterResult.setElem(row, col, band, rasterResult.getElemByte(row, col, renderBands[band])); |
181 |
} |
182 |
} |
183 |
} |
184 |
} |
185 |
|
186 |
/*
|
187 |
* (non-Javadoc)
|
188 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getInRasterDataType()
|
189 |
*/
|
190 |
public int getInRasterDataType() { |
191 |
return 0; |
192 |
} |
193 |
|
194 |
/*
|
195 |
* (non-Javadoc)
|
196 |
* @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
|
197 |
*/
|
198 |
public void process(int x, int y) { |
199 |
} |
200 |
|
201 |
public Object clone() throws CloneNotSupportedException { |
202 |
Object obj = null; |
203 |
obj = super.clone();
|
204 |
return obj;
|
205 |
} |
206 |
} |