root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / LinearEnhancementFilter.java @ 11067
History | View | Annotate | Download (4.89 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.dataaccess.buffer.RasterBuffer; |
22 |
import org.gvsig.raster.dataset.IBuffer; |
23 |
import org.gvsig.raster.dataset.properties.DatasetListStatistics; |
24 |
import org.gvsig.raster.grid.filter.RasterFilter; |
25 |
|
26 |
/**
|
27 |
* Clase base para los filtros de realzado lineal. Lee el m?nimo y m?xmo de la clase
|
28 |
* Statistic que ser?n calculados por PercentTailTrimFilter o ComputeMinMaxFilter dependiendo
|
29 |
* de si est? activado el recorte de colas o no. En Statistic tambi?n est?n los segundos
|
30 |
* valores despu?s del m?nimo y m?ximo que son los que se utilizan con la opci?n eliminar
|
31 |
* extremos activada. Estos se usaran en vez del m?nimo y m?ximo cuando la variable
|
32 |
* removeExtrema est? a true.
|
33 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
34 |
*/
|
35 |
public abstract class LinearEnhancementFilter extends RasterFilter { |
36 |
public static String genericName = "enhanced"; |
37 |
|
38 |
protected double[] scale = new double[3]; |
39 |
protected double[] offset = new double[3]; |
40 |
protected DatasetListStatistics stats = null; |
41 |
|
42 |
protected double[] minBandValue = null; |
43 |
protected double[] maxBandValue = null; |
44 |
|
45 |
protected boolean removeEnds = false; |
46 |
protected double tailTrim = 0D; |
47 |
protected IBuffer rasterResult = null; |
48 |
protected int nbands = 3; |
49 |
|
50 |
/**
|
51 |
* Constructor
|
52 |
*
|
53 |
*/
|
54 |
public LinearEnhancementFilter() {
|
55 |
super();
|
56 |
super.fName = genericName;
|
57 |
this.fPriority = 21; |
58 |
} |
59 |
|
60 |
/* (non-Javadoc)
|
61 |
* @see org.cresques.io.raster.IRasterFilter#pre()
|
62 |
*/
|
63 |
public void pre() { |
64 |
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 |
height = raster.getHeight(); |
69 |
width = raster.getWidth(); |
70 |
|
71 |
if(tailTrim != 0){ //Max y Min con recorte de colas |
72 |
double[][] tailTrimByBand = (double[][])stats.getTailTrimValue(tailTrim); |
73 |
scale = new double[tailTrimByBand.length]; |
74 |
offset = new double[tailTrimByBand.length]; |
75 |
minBandValue = new double[tailTrimByBand.length]; |
76 |
maxBandValue = new double[tailTrimByBand.length]; |
77 |
for(int i = 0; i < tailTrimByBand.length; i++){ |
78 |
minBandValue[i] = tailTrimByBand[i][0];
|
79 |
maxBandValue[i] = tailTrimByBand[i][1];
|
80 |
} |
81 |
}else{
|
82 |
scale = new double[stats.getMin().length]; |
83 |
offset = new double[stats.getMin().length]; |
84 |
if (removeEnds) { //Si est? activado eliminar extremos gastamos el 2? m?ximo/m?nimo |
85 |
minBandValue = stats.getSecondMin(); |
86 |
maxBandValue = stats.getSecondMax(); |
87 |
} else { //Si no est? activado eliminar extremos |
88 |
minBandValue = stats.getMin(); |
89 |
maxBandValue = stats.getMax(); |
90 |
} |
91 |
} |
92 |
|
93 |
for (int i = 0; i < minBandValue.length; i++) { |
94 |
scale[i] = 255D / (maxBandValue[i] - minBandValue[i]);
|
95 |
offset[i] = (255D * minBandValue[i]) / (minBandValue[i] -
|
96 |
maxBandValue[i]); |
97 |
} |
98 |
|
99 |
nbands = stats.getBandCount(); |
100 |
rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true, null); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Obtiene true si est? activado el flag de eliminar extremos y false si no lo est?
|
105 |
*/
|
106 |
public Boolean getRemoveEnds() { |
107 |
return new Boolean(removeEnds); |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Obtiene el porcentaje de recorte de colas aplicado o 0 si no tiene.
|
112 |
* @return
|
113 |
*/
|
114 |
public Double getTailTrim(){ |
115 |
return new Double(tailTrim); |
116 |
} |
117 |
|
118 |
/*
|
119 |
* (non-Javadoc)
|
120 |
* @see org.gvsig.fmap.grid.filter.IRasterFilter#getOutRasterDataType()
|
121 |
*/
|
122 |
public int getOutRasterDataType() { |
123 |
return IBuffer.TYPE_BYTE;
|
124 |
} |
125 |
|
126 |
/*
|
127 |
* (non-Javadoc)
|
128 |
* @see org.gvsig.fmap.grid.filter.IRasterFilter#getResult(java.lang.String)
|
129 |
*/
|
130 |
public Object getResult(String name) { |
131 |
return (Object) this.rasterResult; |
132 |
} |
133 |
} |