gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / enhancement / DefaultLinearStretchParams.java @ 2438
History | View | Annotate | Download (6.68 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.grid.filter.enhancement; |
23 |
|
24 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
25 |
import org.gvsig.fmap.dal.coverage.datastruct.Stretch; |
26 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
27 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
28 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
29 |
import org.gvsig.fmap.dal.coverage.grid.filter.LinearStretchParams; |
30 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
31 |
import org.gvsig.raster.impl.datastruct.DefaultStretch; |
32 |
/**
|
33 |
* Par?metros necesarios para el filtro de realce por tramos. Contiene
|
34 |
* informaci?n de cada tramo. Valores m?ximos y m?nimos reales y correspondencia
|
35 |
* a RGB de cada tramo.
|
36 |
*
|
37 |
* Tambi?n contiene los valores calculados en el preproceso de escala y
|
38 |
* desplazamiento para cada banda.
|
39 |
*
|
40 |
* @author Nacho Brodin nachobrodin@gmail.com
|
41 |
*/
|
42 |
public class DefaultLinearStretchParams implements LinearStretchParams { |
43 |
public DefaultStretch red = new DefaultStretch(); |
44 |
public DefaultStretch green = new DefaultStretch(); |
45 |
public DefaultStretch blue = new DefaultStretch(); |
46 |
public boolean rgb = false; |
47 |
|
48 |
public boolean hasTailTrim() { |
49 |
return (red.hasTailTrim() ||
|
50 |
green.hasTailTrim() || |
51 |
blue.hasTailTrim()); |
52 |
} |
53 |
|
54 |
public double[] getTailTrimList() { |
55 |
return new double[]{ |
56 |
red.tailTrimMin, green.tailTrimMin, blue.tailTrimMin, |
57 |
red.tailTrimMax, green.tailTrimMax, blue.tailTrimMax}; |
58 |
} |
59 |
|
60 |
public void loadTailTrimValues(Statistics stats) { |
61 |
double[][] result; |
62 |
result = (double[][]) stats.getTailTrimValue(red.tailTrimMin); |
63 |
if (result != null) |
64 |
red.tailTrimValueMin = result[0][0]; |
65 |
result = (double[][]) stats.getTailTrimValue(red.tailTrimMax); |
66 |
if (result != null) |
67 |
red.tailTrimValueMax = result[0][1]; |
68 |
result = (double[][]) stats.getTailTrimValue(green.tailTrimMin); |
69 |
if (result != null && result.length >= 2) |
70 |
green.tailTrimValueMin = result[1][0]; |
71 |
result = (double[][]) stats.getTailTrimValue(green.tailTrimMax); |
72 |
if (result != null && result.length >= 2) |
73 |
green.tailTrimValueMax = result[1][1]; |
74 |
result = (double[][]) stats.getTailTrimValue(blue.tailTrimMin); |
75 |
if (result != null && result.length >= 3) |
76 |
blue.tailTrimValueMin = result[2][0]; |
77 |
result = (double[][]) stats.getTailTrimValue(blue.tailTrimMax); |
78 |
if (result != null && result.length >= 3) |
79 |
blue.tailTrimValueMax = result[2][1]; |
80 |
} |
81 |
|
82 |
public void applyTrimToStretchs() { |
83 |
red.applyTrimToStretchs(); |
84 |
green.applyTrimToStretchs(); |
85 |
blue.applyTrimToStretchs(); |
86 |
} |
87 |
|
88 |
public void calcLinearScaleAndOffset() { |
89 |
red.calcLinearScaleAndOffset(); |
90 |
green.calcLinearScaleAndOffset(); |
91 |
blue.calcLinearScaleAndOffset(); |
92 |
} |
93 |
|
94 |
public void setMaxMin(Statistics stats, int[] renderBands) { |
95 |
if (renderBands[0] > -1) |
96 |
red.setMaxMin(stats, renderBands[0], rgb);
|
97 |
if (renderBands[1] > -1) |
98 |
green.setMaxMin(stats, renderBands[1], rgb);
|
99 |
if (renderBands[2] > -1) |
100 |
blue.setMaxMin(stats, renderBands[2], rgb);
|
101 |
} |
102 |
|
103 |
public void applyRemoveEndsToStretchs(Statistics stats, int[] renderBands) { |
104 |
if (renderBands[0] > -1) |
105 |
red.applyRemoveEndsToStretchs(stats, rgb, renderBands[0]);
|
106 |
if (renderBands[1] > -1) |
107 |
green.applyRemoveEndsToStretchs(stats, rgb, renderBands[1]);
|
108 |
if (renderBands[2] > -1) |
109 |
blue.applyRemoveEndsToStretchs(stats, rgb, renderBands[2]);
|
110 |
} |
111 |
|
112 |
/**
|
113 |
* Obtiene un objeto LinearStretchParams para una aplicaci?n de realce lineal estandar, es decir, el rango
|
114 |
* de datos de salida es 0-255 y con solo un tramo para los datos.
|
115 |
* @param nBands N?mero de bandas
|
116 |
* @param tailTrim Recorte de colas
|
117 |
* @param stats Estad?sticas
|
118 |
* @return LinearStretchParams
|
119 |
* @throws FileNotOpenException
|
120 |
* @throws RasterDriverException
|
121 |
*/
|
122 |
public static DefaultLinearStretchParams createStandardParam(int[] renderBands, double tailTrim, Statistics stats, boolean rgb) throws FileNotOpenException, RasterDriverException { |
123 |
DefaultLinearStretchParams leParams = new DefaultLinearStretchParams();
|
124 |
leParams.rgb = rgb; |
125 |
try {
|
126 |
stats.calculate(RasterLibrary.statisticsScale); |
127 |
} catch (ProcessInterruptedException e) {
|
128 |
return null; |
129 |
} |
130 |
if (renderBands[0] >= 0) { |
131 |
if (rgb)
|
132 |
leParams.red.stretchIn = new double[] { stats.getMinByteUnsigned()[0], stats.getMaxByteUnsigned()[0] }; |
133 |
else
|
134 |
leParams.red.stretchIn = new double[] { stats.getMin()[renderBands[0]], stats.getMax()[renderBands[0]] }; |
135 |
} |
136 |
leParams.red.stretchOut = new int[] { 0, 255 }; |
137 |
leParams.red.tailTrimMin = tailTrim; |
138 |
leParams.red.tailTrimMax = tailTrim; |
139 |
if (renderBands[1] >= 0) { |
140 |
if (rgb)
|
141 |
leParams.green.stretchIn = new double[] { stats.getMinByteUnsigned()[0], stats.getMaxByteUnsigned()[0] }; |
142 |
else
|
143 |
leParams.green.stretchIn = new double[] { stats.getMin()[renderBands[1]], stats.getMax()[renderBands[1]] }; |
144 |
} |
145 |
leParams.green.stretchOut = new int[] { 0, 255 }; |
146 |
leParams.green.tailTrimMin = tailTrim; |
147 |
leParams.green.tailTrimMax = tailTrim; |
148 |
if (renderBands[2] >= 0) { |
149 |
if (rgb)
|
150 |
leParams.blue.stretchIn = new double[] { stats.getMinByteUnsigned()[0], stats.getMaxByteUnsigned()[0] }; |
151 |
else
|
152 |
leParams.blue.stretchIn = new double[] { stats.getMin()[renderBands[2]], stats.getMax()[renderBands[2]] }; |
153 |
} |
154 |
leParams.blue.stretchOut = new int[] { 0, 255 }; |
155 |
leParams.blue.tailTrimMin = tailTrim; |
156 |
leParams.blue.tailTrimMax = tailTrim; |
157 |
return leParams;
|
158 |
} |
159 |
|
160 |
public Stretch getRed() {
|
161 |
return red;
|
162 |
} |
163 |
|
164 |
public void setRed(Stretch red) { |
165 |
this.red = (DefaultStretch)red;
|
166 |
} |
167 |
|
168 |
public Stretch getGreen() {
|
169 |
return green;
|
170 |
} |
171 |
|
172 |
public void setGreen(Stretch green) { |
173 |
this.green = (DefaultStretch)green;
|
174 |
} |
175 |
|
176 |
public Stretch getBlue() {
|
177 |
return blue;
|
178 |
} |
179 |
|
180 |
public void setBlue(Stretch blue) { |
181 |
this.blue = (DefaultStretch)blue;
|
182 |
} |
183 |
|
184 |
public boolean isRgb() { |
185 |
return rgb;
|
186 |
} |
187 |
|
188 |
public void setRgb(boolean rgb) { |
189 |
this.rgb = rgb;
|
190 |
} |
191 |
} |