svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / LinearEnhancementFilter.java @ 19494
History | View | Annotate | Download (7.46 KB)
1 | 10740 | nacho | /* 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 | 11076 | nacho | import org.gvsig.raster.buffer.RasterBuffer; |
22 | 19290 | bsanchez | import org.gvsig.raster.dataset.FileNotOpenException; |
23 | 10939 | nacho | import org.gvsig.raster.dataset.IBuffer; |
24 | 11652 | bsanchez | import org.gvsig.raster.dataset.Params; |
25 | 19290 | bsanchez | import org.gvsig.raster.dataset.io.RasterDriverException; |
26 | 10939 | nacho | import org.gvsig.raster.dataset.properties.DatasetListStatistics; |
27 | 10740 | nacho | import org.gvsig.raster.grid.filter.RasterFilter; |
28 | /**
|
||
29 | 11899 | bsanchez | * Clase base para los filtros de realzado lineal. Lee el m?nimo y m?xmo de la
|
30 | * clase Statistic que ser?n calculados por PercentTailTrimFilter o
|
||
31 | * ComputeMinMaxFilter dependiendo de si est? activado el recorte de colas o no.
|
||
32 | * En Statistic tambi?n est?n los segundos valores despu?s del m?nimo y m?ximo
|
||
33 | * que son los que se utilizan con la opci?n eliminar extremos activada. Estos
|
||
34 | * se usaran en vez del m?nimo y m?ximo cuando la variable removeExtrema est? a
|
||
35 | * true.
|
||
36 | 11942 | bsanchez | *
|
37 | * @version 31/05/2007
|
||
38 | 10756 | nacho | * @author Nacho Brodin (nachobrodin@gmail.com)
|
39 | 10740 | nacho | */
|
40 | 11714 | bsanchez | public class LinearEnhancementFilter extends RasterFilter { |
41 | 12476 | nacho | protected double[] scale = new double[3]; |
42 | protected double[] offset = new double[3]; |
||
43 | protected DatasetListStatistics stats = null; |
||
44 | protected double[] minBandValue = null; |
||
45 | protected double[] maxBandValue = null; |
||
46 | protected boolean removeEnds = false; |
||
47 | protected double tailTrim = 0D; |
||
48 | protected int nbands = 3; |
||
49 | protected int[] renderBands = null; |
||
50 | public static String[] names = new String[] {"enhanced"}; |
||
51 | 10740 | nacho | |
52 | 11792 | bsanchez | /**
|
53 | * Construye un LinearEnhancementFilter
|
||
54 | */
|
||
55 | 11942 | bsanchez | public LinearEnhancementFilter() {
|
56 | 11986 | bsanchez | setName(names[0]);
|
57 | 11792 | bsanchez | } |
58 | 10740 | nacho | |
59 | 11942 | bsanchez | /*
|
60 | * (non-Javadoc)
|
||
61 | * @see org.gvsig.raster.grid.filter.RasterFilter#pre()
|
||
62 | */
|
||
63 | public void pre() { |
||
64 | 11792 | bsanchez | raster = (IBuffer) params.get("raster");
|
65 | stats = (DatasetListStatistics) params.get("stats");
|
||
66 | removeEnds = ((Boolean) params.get("remove")).booleanValue(); |
||
67 | tailTrim = ((Double) params.get("tailTrim")).doubleValue(); |
||
68 | 19290 | bsanchez | // En realidad esto no se deberia hacer, pero por logica, un valor del 50%
|
69 | // devolveria una capa en blanco, asi que evitamos un resultado supuestamente
|
||
70 | // no esperado
|
||
71 | if ((tailTrim >= 0.5) && (tailTrim < 0.51)) |
||
72 | tailTrim = 0.51;
|
||
73 | if ((tailTrim > 0.49) && (tailTrim < 0.50)) |
||
74 | tailTrim = 0.49;
|
||
75 | 11792 | bsanchez | renderBands = (int[]) params.get("renderBands"); |
76 | 14412 | nbrodin | if(renderBands != null && renderBands.length < raster.getBandCount()) { |
77 | int[] newRenderBands = new int[raster.getBandCount()]; |
||
78 | for (int i = 0; i < renderBands.length; i++) |
||
79 | newRenderBands[i] = renderBands[i]; |
||
80 | for (int i = renderBands.length; i < newRenderBands.length; i++) |
||
81 | newRenderBands[i] = i; |
||
82 | renderBands = newRenderBands; |
||
83 | } |
||
84 | 11792 | bsanchez | height = raster.getHeight(); |
85 | width = raster.getWidth(); |
||
86 | 10740 | nacho | |
87 | 19290 | bsanchez | try {
|
88 | stats.calcFullStatistics(); |
||
89 | } catch (FileNotOpenException e) {
|
||
90 | exec = false;
|
||
91 | } catch (RasterDriverException e) {
|
||
92 | exec = false;
|
||
93 | } catch (InterruptedException e) { |
||
94 | exec = false;
|
||
95 | 14412 | nbrodin | } |
96 | 19290 | bsanchez | double[][] tailTrimByBand = (double[][]) stats.getTailTrimValue(tailTrim); |
97 | if ((tailTrim != 0) && (tailTrimByBand != null)) { // Max y Min con recorte de colas |
||
98 | scale = new double[tailTrimByBand.length]; |
||
99 | offset = new double[tailTrimByBand.length]; |
||
100 | minBandValue = new double[tailTrimByBand.length]; |
||
101 | maxBandValue = new double[tailTrimByBand.length]; |
||
102 | for (int i = 0; i < tailTrimByBand.length; i++) { |
||
103 | minBandValue[i] = tailTrimByBand[i][0];
|
||
104 | maxBandValue[i] = tailTrimByBand[i][1];
|
||
105 | } |
||
106 | } else {
|
||
107 | scale = new double[stats.getMin().length]; |
||
108 | offset = new double[stats.getMin().length]; |
||
109 | 11942 | bsanchez | if (removeEnds) { // Si est? activado eliminar extremos gastamos el 2? m?ximo/m?nimo |
110 | 19290 | bsanchez | if(raster.getDataType() == IBuffer.TYPE_BYTE) {
|
111 | minBandValue = stats.getSecondMinRGB(); |
||
112 | maxBandValue = stats.getSecondMaxRGB(); |
||
113 | 14354 | nbrodin | } else {
|
114 | 19290 | bsanchez | minBandValue = stats.getSecondMin(); |
115 | maxBandValue = stats.getSecondMax(); |
||
116 | 14354 | nbrodin | } |
117 | 11792 | bsanchez | } else { // Si no est? activado eliminar extremos |
118 | 19290 | bsanchez | if(raster.getDataType() == IBuffer.TYPE_BYTE) {
|
119 | minBandValue = stats.getMinRGB(); |
||
120 | maxBandValue = stats.getMaxRGB(); |
||
121 | 14354 | nbrodin | } else {
|
122 | 19290 | bsanchez | minBandValue = stats.getMin(); |
123 | maxBandValue = stats.getMax(); |
||
124 | 14354 | nbrodin | } |
125 | 11792 | bsanchez | } |
126 | } |
||
127 | |||
128 | for (int i = 0; i < minBandValue.length; i++) { |
||
129 | scale[i] = 255D / (maxBandValue[i] - minBandValue[i]);
|
||
130 | offset[i] = (255D * minBandValue[i]) / (minBandValue[i] - maxBandValue[i]);
|
||
131 | } |
||
132 | |||
133 | nbands = stats.getBandCount(); |
||
134 | rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
|
||
135 | } |
||
136 | |||
137 | 11942 | bsanchez | /**
|
138 | 11792 | bsanchez | * Obtiene true si est? activado el flag de eliminar extremos y false si no lo
|
139 | * est?
|
||
140 | */
|
||
141 | 11942 | bsanchez | public Boolean getRemoveEnds() { |
142 | 11792 | bsanchez | return new Boolean(removeEnds); |
143 | } |
||
144 | 11942 | bsanchez | |
145 | /**
|
||
146 | 11792 | bsanchez | * Obtiene el porcentaje de recorte de colas aplicado o 0 si no tiene.
|
147 | * @return
|
||
148 | */
|
||
149 | 11942 | bsanchez | public Double getTailTrim(){ |
150 | return new Double(tailTrim); |
||
151 | } |
||
152 | |||
153 | /*
|
||
154 | * (non-Javadoc)
|
||
155 | * @see org.gvsig.raster.grid.filter.RasterFilter#getOutRasterDataType()
|
||
156 | */
|
||
157 | public int getOutRasterDataType() { |
||
158 | 10740 | nacho | return IBuffer.TYPE_BYTE;
|
159 | } |
||
160 | 11792 | bsanchez | |
161 | 11942 | bsanchez | /*
|
162 | * (non-Javadoc)
|
||
163 | * @see org.gvsig.raster.grid.filter.RasterFilter#getResult(java.lang.String)
|
||
164 | */
|
||
165 | 10740 | nacho | public Object getResult(String name) { |
166 | 12008 | bsanchez | if (name.equals("raster")) |
167 | 17108 | nbrodin | if(!exec)
|
168 | return (Object) this.raster; |
||
169 | else
|
||
170 | return (Object) this.rasterResult; |
||
171 | 12008 | bsanchez | return null; |
172 | 10740 | nacho | } |
173 | 11942 | bsanchez | |
174 | 11652 | bsanchez | /*
|
175 | * (non-Javadoc)
|
||
176 | 11942 | bsanchez | * @see org.gvsig.raster.grid.filter.RasterFilter#getGroup()
|
177 | 11652 | bsanchez | */
|
178 | public String getGroup() { |
||
179 | 15855 | nbrodin | return "radiometricos"; |
180 | 11652 | bsanchez | } |
181 | 11942 | bsanchez | |
182 | 11652 | bsanchez | /*
|
183 | * (non-Javadoc)
|
||
184 | 11942 | bsanchez | * @see org.gvsig.raster.grid.filter.RasterFilter#getUIParams()
|
185 | 11652 | bsanchez | */
|
186 | 12030 | bsanchez | public Params getUIParams(String nameFilter) { |
187 | 11714 | bsanchez | Params params = new Params();
|
188 | 11786 | bsanchez | params.setParam("RemoveEnds",
|
189 | 14249 | nbrodin | new Boolean(removeEnds), |
190 | 11786 | bsanchez | Params.CHECK, |
191 | null);
|
||
192 | params.setParam("TailTrim",
|
||
193 | 14249 | nbrodin | new Double(Math.round(tailTrim * 100.0)), |
194 | 11786 | bsanchez | Params.SLIDER, |
195 | new String[]{ "0", "100", "0", "1", "25" }); //min, max, valor defecto, intervalo peque?o, intervalo grande; |
||
196 | 11714 | bsanchez | return params;
|
197 | 11652 | bsanchez | } |
198 | |||
199 | /*
|
||
200 | * (non-Javadoc)
|
||
201 | 11711 | nacho | * @see org.gvsig.raster.grid.filter.RasterFilter#post()
|
202 | */
|
||
203 | public void post() { |
||
204 | 11899 | bsanchez | // En caso de que nadie apunte a raster, se liberar? su memoria.
|
205 | raster = null;
|
||
206 | 11711 | nacho | } |
207 | 11714 | bsanchez | |
208 | /*
|
||
209 | * (non-Javadoc)
|
||
210 | * @see org.gvsig.raster.grid.filter.RasterFilter#getInRasterDataType()
|
||
211 | */
|
||
212 | public int getInRasterDataType() { |
||
213 | return 0; |
||
214 | } |
||
215 | |||
216 | /*
|
||
217 | * (non-Javadoc)
|
||
218 | * @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
|
||
219 | */
|
||
220 | public void process(int x, int y) { |
||
221 | } |
||
222 | 11963 | bsanchez | |
223 | /*
|
||
224 | * (non-Javadoc)
|
||
225 | * @see org.gvsig.raster.grid.filter.RasterFilter#getNames()
|
||
226 | */
|
||
227 | public String[] getNames() { |
||
228 | return names;
|
||
229 | } |
||
230 | 13594 | nacho | |
231 | /*
|
||
232 | * (non-Javadoc)
|
||
233 | * @see org.gvsig.raster.grid.filter.RasterFilter#isVisible()
|
||
234 | */
|
||
235 | public boolean isVisible() { |
||
236 | 14384 | nbrodin | return true; |
237 | 13594 | nacho | } |
238 | 11652 | bsanchez | } |