svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / histogramMatching / HistogramMatchingFilter.java @ 21065
History | View | Annotate | Download (4.92 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Iba?ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.raster.grid.filter.histogramMatching; |
42 |
|
43 |
import org.gvsig.raster.buffer.RasterBuffer; |
44 |
import org.gvsig.raster.dataset.Params; |
45 |
import org.gvsig.raster.datastruct.Histogram; |
46 |
import org.gvsig.raster.datastruct.HistogramException; |
47 |
import org.gvsig.raster.grid.filter.RasterFilter; |
48 |
|
49 |
/**
|
50 |
* Filtro para la aplicaci?n de HistogramMatching a un raster.
|
51 |
*
|
52 |
* @author aMu?oz (alejandro.munoz@uclm.es)
|
53 |
* @version 27-5-2008
|
54 |
*
|
55 |
* */
|
56 |
|
57 |
public class HistogramMatchingFilter extends RasterFilter { |
58 |
|
59 |
public static String[] names = new String[] {"HistogramMatch"}; |
60 |
|
61 |
Histogram histogramReference = null;
|
62 |
Histogram histogramSource= null;
|
63 |
double [][] acumulateS= null; |
64 |
double [][]acumulateR = null; |
65 |
String fileNameOutput = null; |
66 |
byte tableAsign[][]= new byte[3][256]; |
67 |
|
68 |
/** Constructor */
|
69 |
public HistogramMatchingFilter() {
|
70 |
super();
|
71 |
} |
72 |
|
73 |
public String getGroup() { |
74 |
return "HistogramMatch"; |
75 |
} |
76 |
|
77 |
public int getInRasterDataType() { |
78 |
return 0; |
79 |
} |
80 |
|
81 |
public String[] getNames() { |
82 |
return names;
|
83 |
} |
84 |
|
85 |
public int getOutRasterDataType() { |
86 |
return RasterBuffer.TYPE_BYTE;
|
87 |
} |
88 |
|
89 |
|
90 |
public Params getUIParams(String nameFilter) { |
91 |
Params params = new Params();
|
92 |
return params;
|
93 |
} |
94 |
|
95 |
|
96 |
public boolean isVisible() { |
97 |
return false; |
98 |
} |
99 |
|
100 |
|
101 |
/**
|
102 |
* Acciones antes de la ejecuci?n del filtro
|
103 |
* */
|
104 |
public void pre() { |
105 |
// Carga de los parametros del filtro y obtencion de histogramas
|
106 |
loadParam(); |
107 |
|
108 |
// Funcion que calcula la correspondencia entre los histogramas, El resultado es tableAsign completa
|
109 |
// para cada clase en el histograma fuente asigan su clase en el histograma corregido.
|
110 |
double inValue=0; |
111 |
|
112 |
// C?lculo de la tabla de asignaciones entre los histogramas
|
113 |
for (int band=0; band <3; band++){ |
114 |
for(int i= 0; i< tableAsign[0].length; i++){ |
115 |
inValue = acumulateS[band][i]; |
116 |
int value= (searchInHistogramReference(inValue,band));
|
117 |
tableAsign[band][i]= (byte)value;
|
118 |
} |
119 |
} |
120 |
} |
121 |
|
122 |
|
123 |
/**
|
124 |
* Acciones posteriores a la ejecuci?n del filtro
|
125 |
* */
|
126 |
public void post() { |
127 |
} |
128 |
|
129 |
|
130 |
|
131 |
public Object getResult(String name) { |
132 |
return rasterResult;
|
133 |
} |
134 |
|
135 |
|
136 |
/**
|
137 |
* Se recogen los parametros necesarios para la aplicacion del filtro.
|
138 |
* histogramReference histograma de referencia.
|
139 |
* fileNameOutput
|
140 |
*
|
141 |
*/
|
142 |
protected void loadParam(){ |
143 |
// Raster
|
144 |
raster= (RasterBuffer) params.get("raster");
|
145 |
try {
|
146 |
|
147 |
histogramSource= raster.getHistogram(); |
148 |
histogramSource = Histogram.convertHistogramToRGB(histogramSource); |
149 |
|
150 |
// COMPROBACION HISTOGRAMA RGB
|
151 |
if(histogramSource.getMax()>255 || histogramSource.getMin()>0) |
152 |
return;
|
153 |
|
154 |
// Histograma de referencia
|
155 |
histogramReference= (Histogram)params.get("histogramReference");
|
156 |
histogramReference = Histogram.convertHistogramToRGB(histogramReference); |
157 |
|
158 |
// Histogramas acumilados y normalizados
|
159 |
acumulateS = Histogram.convertTableToNormalizeAccumulate(histogramSource.getTable()); |
160 |
acumulateR= Histogram.convertTableToNormalizeAccumulate(histogramReference.getTable()); |
161 |
|
162 |
} catch (HistogramException e) {
|
163 |
|
164 |
} catch (InterruptedException e) { |
165 |
|
166 |
} |
167 |
rasterResult= RasterBuffer.getBuffer(RasterBuffer.TYPE_BYTE,raster.getWidth(),raster.getHeight(),raster.getBandCount(),true);
|
168 |
fileNameOutput= (String)params.get("fileNameOutput"); |
169 |
} |
170 |
|
171 |
|
172 |
/**
|
173 |
* M?todo que realiza la correspondencia entre las clases de los histogramas
|
174 |
* */
|
175 |
public int searchInHistogramReference(double value,int band){ |
176 |
int i=0; |
177 |
while(value>acumulateR[band][i]){
|
178 |
i++; |
179 |
if(i==255) |
180 |
return (int)255; |
181 |
} |
182 |
if(i==0) |
183 |
return 0; |
184 |
if((acumulateR[band][i]-value) < (acumulateR[band][i-1]-value)) |
185 |
return (int)i; |
186 |
else
|
187 |
return (int)(i-1); |
188 |
} |
189 |
|
190 |
public void process(int x, int y) { |
191 |
// TODO Auto-generated method stub
|
192 |
|
193 |
} |
194 |
|
195 |
} |