root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / imagefusion / process / BroveyFusionProcess.java @ 27361
History | View | Annotate | Download (12.6 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Iba?ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
35 |
* Campus Universitario s/n
|
36 |
* 02071 Alabacete
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 967 599 200
|
40 |
*/
|
41 |
|
42 |
package org.gvsig.remotesensing.imagefusion.process; |
43 |
|
44 |
import org.gvsig.raster.buffer.RasterBuffer; |
45 |
import org.gvsig.raster.util.RasterToolsUtil; |
46 |
|
47 |
import com.iver.andami.PluginServices; |
48 |
|
49 |
|
50 |
/**
|
51 |
* Proceso Brovey.
|
52 |
*
|
53 |
* @version 27/02/2008
|
54 |
* @author Alejandro Mu?oz S?nchez (alejandro.munoz@uclm.es)
|
55 |
*
|
56 |
*/
|
57 |
public class BroveyFusionProcess extends ImageFusionProcess{ |
58 |
|
59 |
public void init(){ |
60 |
super.init();
|
61 |
} |
62 |
|
63 |
/** Proceso de construccion de la imagen resultado de la fusion*/
|
64 |
public void process() throws InterruptedException { |
65 |
|
66 |
byte [][] pRGBMultiespectralByte = null; |
67 |
short [][] pRGBMultiespectralShort = null; |
68 |
int [][] pRGBMultiespectralInt = null; |
69 |
float [][] pRGBMultiespectralFloat = null; |
70 |
double [][] pRGBMultiespectralDouble = null; |
71 |
|
72 |
int heightMultiespec = inputGrid.getRasterBuf().getHeight();
|
73 |
insertLineLog(RasterToolsUtil.getText(this, "aplicando_brovey")); |
74 |
|
75 |
|
76 |
// Caso Bufer tipo byte
|
77 |
if(inputGrid.getRasterBuf().getDataType()== RasterBuffer.TYPE_BYTE){
|
78 |
rasterResult= RasterBuffer.getBuffer(RasterBuffer.TYPE_BYTE, highBandGrid.getRasterBuf().getWidth(), highBandGrid.getRasterBuf().getHeight(), 3, true); |
79 |
for(int iLine=0;iLine<heightMultiespec ;iLine++){ |
80 |
pRGBMultiespectralByte = inputGrid.getRasterBuf().getLineByte(iLine); |
81 |
processBrovey(pRGBMultiespectralByte, iLine); |
82 |
percent= (int)iLine*100/heightMultiespec; |
83 |
} |
84 |
} |
85 |
|
86 |
// Caso Bufer tipo short
|
87 |
if(inputGrid.getRasterBuf().getDataType()== RasterBuffer.TYPE_SHORT){
|
88 |
|
89 |
rasterResult= RasterBuffer.getBuffer(RasterBuffer.TYPE_SHORT, highBandGrid.getRasterBuf().getWidth(), highBandGrid.getRasterBuf().getHeight(), 3, true); |
90 |
for(int iLine=0;iLine<heightMultiespec ;iLine++){ |
91 |
pRGBMultiespectralShort = inputGrid.getRasterBuf().getLineShort(iLine); |
92 |
processBrovey(pRGBMultiespectralShort, iLine); |
93 |
percent= (int)iLine*100/heightMultiespec; |
94 |
|
95 |
} |
96 |
|
97 |
} |
98 |
|
99 |
// Caso Bufer tipo int
|
100 |
if(inputGrid.getRasterBuf().getDataType()== RasterBuffer.TYPE_INT){
|
101 |
|
102 |
rasterResult= RasterBuffer.getBuffer(RasterBuffer.TYPE_INT, highBandGrid.getRasterBuf().getWidth(), highBandGrid.getRasterBuf().getHeight(), 3, true); |
103 |
for(int iLine=0;iLine<heightMultiespec ;iLine++){ |
104 |
pRGBMultiespectralInt = inputGrid.getRasterBuf().getLineInt(iLine); |
105 |
processBrovey(pRGBMultiespectralInt, iLine); |
106 |
percent= (int)iLine*100/heightMultiespec; |
107 |
} |
108 |
} |
109 |
|
110 |
// Caso Bufer tipo float
|
111 |
if(inputGrid.getRasterBuf().getDataType()== RasterBuffer.TYPE_FLOAT){
|
112 |
|
113 |
rasterResult= RasterBuffer.getBuffer(RasterBuffer.TYPE_FLOAT, highBandGrid.getRasterBuf().getWidth(), highBandGrid.getRasterBuf().getHeight(), 3, true); |
114 |
for(int iLine=0;iLine<heightMultiespec ;iLine++){ |
115 |
pRGBMultiespectralFloat = inputGrid.getRasterBuf().getLineFloat(iLine); |
116 |
processBrovey(pRGBMultiespectralFloat, iLine); |
117 |
percent= (int)iLine*100/heightMultiespec; |
118 |
} |
119 |
} |
120 |
|
121 |
// Caso Bufer tipo double
|
122 |
if(inputGrid.getRasterBuf().getDataType()== RasterBuffer.TYPE_DOUBLE){
|
123 |
|
124 |
rasterResult= RasterBuffer.getBuffer(RasterBuffer.TYPE_DOUBLE, highBandGrid.getRasterBuf().getWidth(), highBandGrid.getRasterBuf().getHeight(), 3, true); |
125 |
for(int iLine=0;iLine<heightMultiespec ;iLine++){ |
126 |
pRGBMultiespectralFloat = inputGrid.getRasterBuf().getLineFloat(iLine); |
127 |
processBrovey(pRGBMultiespectralDouble, iLine); |
128 |
percent= (int)iLine*100/heightMultiespec; |
129 |
} |
130 |
} |
131 |
|
132 |
writeToFile(); |
133 |
} |
134 |
|
135 |
|
136 |
/**
|
137 |
* Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene
|
138 |
* el RGB que es pasado por par?metro utilizando la pancrom?tica.
|
139 |
* @param bufferInput Buffer rgb
|
140 |
* @param length longitud del buffer de la pancromatica utilizado
|
141 |
* @param iLine l?nea leida de la imagen multiespectral
|
142 |
* @return
|
143 |
* @throws InterruptedException
|
144 |
*/
|
145 |
private void processBrovey(byte[][] bufferInput, int iLine) throws InterruptedException { |
146 |
int r=0,g=0,b=0; |
147 |
double r1=0, g1=0, b1=0; |
148 |
double scale=0; |
149 |
double valorPanc=0; |
150 |
int line=0, col=0; |
151 |
// Para cada elemento Punto de la multiespectral
|
152 |
for(int iElem=0; iElem<bufferInput[0].length; iElem++){ |
153 |
r = (int)(bufferInput[0][iElem]& 0xff); |
154 |
g = (int) (bufferInput[1][iElem]&0xff); |
155 |
b = (int)(bufferInput[2][iElem]& 0xff); |
156 |
for(int j=0;j<cellFactorX;j++){ |
157 |
for(int k=0;k<cellFactorY;k++){ |
158 |
line=(int) (iLine*cellFactorY+j);
|
159 |
col= (int) (iElem*cellFactorX+k);
|
160 |
valorPanc = getValuePanc(line, col); |
161 |
scale = (3*(valorPanc+coef))/(r+g+b+1.0); |
162 |
r1 = r*scale; |
163 |
g1 = g*scale; |
164 |
b1 = b*scale; |
165 |
|
166 |
// Evitar desbordamiento ???
|
167 |
if(r1>255) r1=255; |
168 |
if(g1>255) g1=255; |
169 |
if(b1>255) b1=255; |
170 |
rasterResult.setElem(line, col, 0, (byte)r1); |
171 |
rasterResult.setElem(line, col, 1, (byte)g1); |
172 |
rasterResult.setElem(line, col, 2, (byte)b1); |
173 |
} |
174 |
} |
175 |
} |
176 |
} |
177 |
|
178 |
|
179 |
|
180 |
/**
|
181 |
* Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene
|
182 |
* el RGB que es pasado por par?metro utilizando la pancrom?tica.
|
183 |
* @param bufferInput buffer de entrada (tipo short)
|
184 |
* @param length longitud del buffer de la pancromatica utilizado
|
185 |
* @param iLine l?nea leida de la imagen multiespectral
|
186 |
* @return
|
187 |
* @throws InterruptedException
|
188 |
*/
|
189 |
private void processBrovey(short[][] bufferInput, int iLine) throws InterruptedException { |
190 |
int r=0,g=0,b=0; |
191 |
double r1=0, g1=0, b1=0; |
192 |
double scale=0; |
193 |
double valorPanc=0; |
194 |
int line=0, col=0; |
195 |
// Para cada elemento Punto de la multiespectral
|
196 |
for(int iElem=0; iElem<bufferInput[0].length; iElem++){ |
197 |
r = (int)(bufferInput[0][iElem]& 0xff); |
198 |
g = (int) (bufferInput[1][iElem]&0xff); |
199 |
b = (int)(bufferInput[2][iElem]& 0xff); |
200 |
for(int j=0;j<cellFactorX;j++){ |
201 |
for(int k=0;k<cellFactorY;k++){ |
202 |
line=(int) (iLine*cellFactorY+j);
|
203 |
col= (int) (iElem*cellFactorX+k);
|
204 |
valorPanc = getValuePanc(line, col);//(highBandGrid.getRasterBuf().getElemByte(line,col,0)&0xff);
|
205 |
scale = (3*(valorPanc+coef))/(r+g+b+1.0); |
206 |
r1 = r*scale; |
207 |
g1 = g*scale; |
208 |
b1 = b*scale; |
209 |
|
210 |
// Evitar desbordamiento ???
|
211 |
if(r1>255) r1=255; |
212 |
if(g1>255) g1=255; |
213 |
if(b1>255) b1=255; |
214 |
rasterResult.setElem(line, col, 0, (short)r1); |
215 |
rasterResult.setElem(line, col, 1, (short)g1); |
216 |
rasterResult.setElem(line, col, 2, (short)b1); |
217 |
} |
218 |
} |
219 |
} |
220 |
|
221 |
} |
222 |
|
223 |
|
224 |
/**
|
225 |
* Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene
|
226 |
* el RGB que es pasado por par?metro utilizando la pancrom?tica.
|
227 |
* @param bufferInput buffer de entrada (tipo int)
|
228 |
* @param length longitud del buffer de la pancromatica utilizado
|
229 |
* @param iLine l?nea leida de la imagen multiespectral
|
230 |
* @return
|
231 |
* @throws InterruptedException
|
232 |
*/
|
233 |
private void processBrovey(int[][] bufferInput, int iLine) throws InterruptedException { |
234 |
int r=0,g=0,b=0; |
235 |
double r1=0, g1=0, b1=0; |
236 |
double scale=0; |
237 |
double valorPanc=0; |
238 |
int line=0, col=0; |
239 |
// Para cada elemento Punto de la multiespectral
|
240 |
for(int iElem=0; iElem<bufferInput[0].length; iElem++){ |
241 |
r = (int)bufferInput[0][iElem]; |
242 |
g = (int)bufferInput[1][iElem]; |
243 |
b = (int)bufferInput[2][iElem]; |
244 |
for(int j=0;j<cellFactorX;j++){ |
245 |
for(int k=0;k<cellFactorY;k++){ |
246 |
line=(int) (iLine*cellFactorY+j);
|
247 |
col= (int) (iElem*cellFactorX+k);
|
248 |
valorPanc = getValuePanc(line, col);//(highBandGrid.getRasterBuf().getElemByte(line,col,0)&0xff);
|
249 |
scale = (3*(valorPanc+coef))/(r+g+b+1.0); |
250 |
r1 = r*scale; |
251 |
g1 = g*scale; |
252 |
b1 = b*scale; |
253 |
rasterResult.setElem(line, col, 0, (int)r1); |
254 |
rasterResult.setElem(line, col, 1, (int)g1); |
255 |
rasterResult.setElem(line, col, 2, (int)b1); |
256 |
} |
257 |
} |
258 |
} |
259 |
|
260 |
} |
261 |
|
262 |
/**
|
263 |
* Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene
|
264 |
* el RGB que es pasado por par?metro utilizando la pancrom?tica.
|
265 |
* @param bufferInput buffer de entrada (tipo float)
|
266 |
* @param length longitud del buffer de la pancromatica utilizado
|
267 |
* @param iLine l?nea leida de la imagen multiespectral
|
268 |
* @return
|
269 |
* @throws InterruptedException
|
270 |
*/
|
271 |
private void processBrovey(float[][] bufferInput, int iLine) throws InterruptedException { |
272 |
float r=0,g=0,b=0; |
273 |
double r1=0, g1=0, b1=0; |
274 |
double scale=0; |
275 |
double valorPanc=0; |
276 |
int line=0, col=0; |
277 |
// Para cada elemento Punto de la multiespectral
|
278 |
for(int iElem=0; iElem<bufferInput[0].length; iElem++){ |
279 |
r = (float)bufferInput[0][iElem]; |
280 |
g = (float)bufferInput[1][iElem]; |
281 |
b = (float)bufferInput[2][iElem]; |
282 |
for(int j=0;j<cellFactorX;j++){ |
283 |
for(int k=0;k<cellFactorY;k++){ |
284 |
line=(int) (iLine*cellFactorY+j);
|
285 |
col= (int) (iElem*cellFactorX+k);
|
286 |
valorPanc = getValuePanc(line, col);//(highBandGrid.getRasterBuf().getElemByte(line,col,0)&0xff);
|
287 |
scale = (3*(valorPanc+coef))/(r+g+b+1.0); |
288 |
r1 = r*scale; |
289 |
g1 = g*scale; |
290 |
b1 = b*scale; |
291 |
rasterResult.setElem(line, col, 0, (float)r1); |
292 |
rasterResult.setElem(line, col, 1, (float)g1); |
293 |
rasterResult.setElem(line, col, 2, (float)b1); |
294 |
} |
295 |
} |
296 |
} |
297 |
} |
298 |
|
299 |
/**
|
300 |
* Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene
|
301 |
* el RGB que es pasado por par?metro utilizando la pancrom?tica.
|
302 |
* @param bufferInput buffer de entrada (tipo double)
|
303 |
* @param length longitud del buffer de la pancromatica utilizado
|
304 |
* @param iLine l?nea leida de la imagen multiespectral
|
305 |
* @return
|
306 |
* @throws InterruptedException
|
307 |
*/
|
308 |
private void processBrovey(double[][] bufferInput, int iLine) throws InterruptedException { |
309 |
double r=0,g=0,b=0; |
310 |
double r1=0, g1=0, b1=0; |
311 |
double scale=0; |
312 |
double valorPanc=0; |
313 |
int line=0, col=0; |
314 |
// Para cada elemento Punto de la multiespectral
|
315 |
for(int iElem=0; iElem<bufferInput[0].length; iElem++){ |
316 |
r = (double)bufferInput[0][iElem]; |
317 |
g = (double)bufferInput[1][iElem]; |
318 |
b = (double)bufferInput[2][iElem]; |
319 |
for(int j=0;j<cellFactorX;j++){ |
320 |
for(int k=0;k<cellFactorY;k++){ |
321 |
line=(int) (iLine*cellFactorY+j);
|
322 |
col= (int) (iElem*cellFactorX+k);
|
323 |
valorPanc = getValuePanc(line, col);//(highBandGrid.getRasterBuf().getElemByte(line,col,0)&0xff);
|
324 |
scale = (3*(valorPanc+coef))/(r+g+b+1.0); |
325 |
r1 = r*scale; |
326 |
g1 = g*scale; |
327 |
b1 = b*scale; |
328 |
rasterResult.setElem(line, col, 0, (double)r1); |
329 |
rasterResult.setElem(line, col, 1, (double)g1); |
330 |
rasterResult.setElem(line, col, 2, (double)b1); |
331 |
} |
332 |
} |
333 |
} |
334 |
} |
335 |
|
336 |
|
337 |
/**
|
338 |
* @throws InterruptedException
|
339 |
* @ return valor de la posicion line col de la banda pancrom?tica
|
340 |
*
|
341 |
* */
|
342 |
protected double getValuePanc(int line, int col) throws InterruptedException { |
343 |
|
344 |
double value= 0.0; |
345 |
switch (highBandGrid.getRasterBuf().getDataType()){
|
346 |
case RasterBuffer.TYPE_BYTE:
|
347 |
value= highBandGrid.getRasterBuf().getElemByte(line,col,0)&0xff; |
348 |
break;
|
349 |
case RasterBuffer.TYPE_SHORT:
|
350 |
value= highBandGrid.getRasterBuf().getElemShort(line,col,0)&0xff; |
351 |
break;
|
352 |
case RasterBuffer.TYPE_INT:
|
353 |
value= highBandGrid.getRasterBuf().getElemInt(line,col,0);
|
354 |
break;
|
355 |
case RasterBuffer.TYPE_FLOAT:
|
356 |
value= highBandGrid.getRasterBuf().getElemFloat(line,col,0);
|
357 |
break;
|
358 |
case RasterBuffer.TYPE_DOUBLE:
|
359 |
value= highBandGrid.getRasterBuf().getElemDouble(line,col,0);
|
360 |
} |
361 |
return value;
|
362 |
} |
363 |
|
364 |
|
365 |
|
366 |
/*
|
367 |
* (non-Javadoc)
|
368 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getLog()
|
369 |
*/
|
370 |
public String getLog() { |
371 |
if (writerBufferServer==null) |
372 |
return PluginServices.getText(this,"fusionando_imagen")+"..." +"\n\nM?todo seleccionado:" +PluginServices.getText(this,"brovey"); |
373 |
else
|
374 |
return PluginServices.getText(this,"escribiendo_resultado")+"..."; |
375 |
} |
376 |
} |