Revision 10973
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/DatasetStatistics.java | ||
---|---|---|
317 | 317 |
return tailTrim.get(s); |
318 | 318 |
} |
319 | 319 |
|
320 |
|
|
321 |
/** |
|
322 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
323 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
324 |
* |
|
325 |
* <UL> |
|
326 |
* <LI>m?nimo</LI> |
|
327 |
* <LI>m?ximo</LI> |
|
328 |
* <LI>media</LI> |
|
329 |
* <LI>mediana</LI> |
|
330 |
* <LI>N?mero de pixels</LI> |
|
331 |
* </UL> |
|
332 |
* @param histogram |
|
333 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
334 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
335 |
* @return |
|
336 |
*/ |
|
337 |
public static long[][] getBasicStatsFromHistogram(int[][] histogram, boolean[] bands){ |
|
338 |
if(histogram == null) |
|
339 |
return null; |
|
340 |
return getBasicStatsFromHistogram(histogram, 0, histogram[0].length - 1, bands); |
|
341 |
} |
|
342 |
/** |
|
343 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
344 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
345 |
* |
|
346 |
* <UL> |
|
347 |
* <LI>m?nimo</LI> |
|
348 |
* <LI>m?ximo</LI> |
|
349 |
* <LI>media</LI> |
|
350 |
* <LI>mediana</LI> |
|
351 |
* <LI>N?mero de pixels</LI> |
|
352 |
* </UL> |
|
353 |
* @param histogram |
|
354 |
* @param beginPos Posici?n de inicio del histograma para contabilizar estadisticas |
|
355 |
* @param endPos Posici?n de fin del histograma para contabilizar estadisticas |
|
356 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
357 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
358 |
* @return |
|
359 |
*/ |
|
360 |
public static long[][] getBasicStatsFromHistogram(int[][] histogram, int beginPos, int endPos, boolean[] bands){ |
|
361 |
if(histogram == null) |
|
362 |
return null; |
|
363 |
|
|
364 |
//Contamos el n?mero de bandas para las cuales se calcula la estad?stica |
|
365 |
int bandCount = 0; |
|
366 |
for(int iBand = 0; iBand < bands.length; iBand ++) |
|
367 |
if(bands[iBand]) |
|
368 |
bandCount ++; |
|
369 |
|
|
370 |
int values = 5; |
|
371 |
long[][] res = new long[values][]; |
|
372 |
|
|
373 |
long[] min = new long[bandCount];//M?nimo |
|
374 |
long[] max = new long[bandCount];//M?ximo |
|
375 |
for(int iBand = 0; iBand < bandCount; iBand ++){ |
|
376 |
max[iBand] = beginPos; |
|
377 |
min[iBand] = endPos; |
|
378 |
} |
|
379 |
long[] average = new long[bandCount]; //Valor de pixel medio (Media) |
|
380 |
long[] middle = new long[bandCount]; //Mediana |
|
381 |
long[] nPixelsBand = new long[bandCount];//N?mero de pixels por banda |
|
382 |
|
|
383 |
int showBandCounter = 0; //Contador de bandas de las que hay calcular la estadistica |
|
384 |
for(int iBand = 0; iBand < histogram.length; iBand ++){ |
|
385 |
if(bands[iBand]){ |
|
386 |
int pixels = 0; //N?mero de valores por banda (entre 0 y 255) |
|
387 |
for(int i = beginPos; i <= endPos; i ++){ |
|
388 |
|
|
389 |
//Calculo del m?nimo |
|
390 |
if(histogram[iBand][i] != 0 && i < min[showBandCounter]) |
|
391 |
min[showBandCounter] = i; |
|
392 |
|
|
393 |
//Calculo del m?ximo |
|
394 |
if(histogram[iBand][i] != 0 && i > max[showBandCounter]) |
|
395 |
max[showBandCounter] = i; |
|
396 |
|
|
397 |
//Calculo del n?mero de pixeles |
|
398 |
nPixelsBand[showBandCounter] += (long)histogram[iBand][i]; |
|
399 |
|
|
400 |
if(histogram[iBand][i] != 0) |
|
401 |
pixels ++; |
|
402 |
|
|
403 |
average[showBandCounter] += histogram[iBand][i] * i; |
|
404 |
} |
|
405 |
//Calculo de la media |
|
406 |
try{ |
|
407 |
average[showBandCounter] /= nPixelsBand[showBandCounter]; |
|
408 |
}catch(ArithmeticException exc){ |
|
409 |
average[showBandCounter] = 0; |
|
410 |
} |
|
411 |
|
|
412 |
//Calculo de mediana |
|
413 |
long middlePos = nPixelsBand[showBandCounter] >> 1; |
|
414 |
int aux = 0; |
|
415 |
int i = beginPos; |
|
416 |
for(i = beginPos; aux < middlePos; i++) |
|
417 |
aux += histogram[iBand][i]; |
|
418 |
middle[showBandCounter] = i - 1; |
|
419 |
|
|
420 |
showBandCounter ++; |
|
421 |
} |
|
422 |
} |
|
423 |
|
|
424 |
res[0] = min; |
|
425 |
res[1] = max; |
|
426 |
res[2] = average; |
|
427 |
res[3] = middle; |
|
428 |
res[4] = nPixelsBand; |
|
429 |
return res; |
|
430 |
} |
|
431 |
|
|
432 | 320 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/util/Histogram.java | ||
---|---|---|
182 | 182 |
return getLogaritmicHistogram(); |
183 | 183 |
return null; |
184 | 184 |
} |
185 |
|
|
186 |
/** |
|
187 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
188 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
189 |
* |
|
190 |
* <UL> |
|
191 |
* <LI>m?nimo</LI> |
|
192 |
* <LI>m?ximo</LI> |
|
193 |
* <LI>media</LI> |
|
194 |
* <LI>mediana</LI> |
|
195 |
* <LI>N?mero de pixels</LI> |
|
196 |
* </UL> |
|
197 |
* @param histogram |
|
198 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
199 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
200 |
* @return |
|
201 |
*/ |
|
202 |
public long[][] getBasicStatsFromHistogram(boolean[] bands){ |
|
203 |
if(histogram == null) |
|
204 |
return null; |
|
205 |
return getBasicStatsFromHistogram(0, histogram[0].length - 1, bands); |
|
206 |
} |
|
207 |
/** |
|
208 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
209 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
210 |
* |
|
211 |
* <UL> |
|
212 |
* <LI>m?nimo</LI> |
|
213 |
* <LI>m?ximo</LI> |
|
214 |
* <LI>media</LI> |
|
215 |
* <LI>mediana</LI> |
|
216 |
* <LI>N?mero de pixels</LI> |
|
217 |
* </UL> |
|
218 |
* @param histogram |
|
219 |
* @param beginPos Posici?n de inicio del histograma para contabilizar estadisticas |
|
220 |
* @param endPos Posici?n de fin del histograma para contabilizar estadisticas |
|
221 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
222 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
223 |
* @return |
|
224 |
*/ |
|
225 |
public long[][] getBasicStatsFromHistogram(int beginPos, int endPos, boolean[] bands){ |
|
226 |
if(histogram == null) |
|
227 |
return null; |
|
228 |
|
|
229 |
//Contamos el n?mero de bandas para las cuales se calcula la estad?stica |
|
230 |
int bandCount = 0; |
|
231 |
for(int iBand = 0; iBand < bands.length; iBand ++) |
|
232 |
if(bands[iBand]) |
|
233 |
bandCount ++; |
|
234 |
|
|
235 |
int values = 5; |
|
236 |
long[][] res = new long[values][]; |
|
237 |
|
|
238 |
long[] min = new long[bandCount];//M?nimo |
|
239 |
long[] max = new long[bandCount];//M?ximo |
|
240 |
for(int iBand = 0; iBand < bandCount; iBand ++){ |
|
241 |
max[iBand] = beginPos; |
|
242 |
min[iBand] = endPos; |
|
243 |
} |
|
244 |
long[] average = new long[bandCount]; //Valor de pixel medio (Media) |
|
245 |
long[] middle = new long[bandCount]; //Mediana |
|
246 |
long[] nPixelsBand = new long[bandCount];//N?mero de pixels por banda |
|
247 |
|
|
248 |
int showBandCounter = 0; //Contador de bandas de las que hay calcular la estadistica |
|
249 |
for(int iBand = 0; iBand < histogram.length; iBand ++){ |
|
250 |
if(bands[iBand]){ |
|
251 |
int pixels = 0; //N?mero de valores por banda (entre 0 y 255) |
|
252 |
for(int i = beginPos; i <= endPos; i ++){ |
|
253 |
|
|
254 |
//Calculo del m?nimo |
|
255 |
if(histogram[iBand][i] != 0 && i < min[showBandCounter]) |
|
256 |
min[showBandCounter] = i; |
|
257 |
|
|
258 |
//Calculo del m?ximo |
|
259 |
if(histogram[iBand][i] != 0 && i > max[showBandCounter]) |
|
260 |
max[showBandCounter] = i; |
|
261 |
|
|
262 |
//Calculo del n?mero de pixeles |
|
263 |
nPixelsBand[showBandCounter] += (long)histogram[iBand][i]; |
|
264 |
|
|
265 |
if(histogram[iBand][i] != 0) |
|
266 |
pixels ++; |
|
267 |
|
|
268 |
average[showBandCounter] += histogram[iBand][i] * i; |
|
269 |
} |
|
270 |
//Calculo de la media |
|
271 |
try{ |
|
272 |
average[showBandCounter] /= nPixelsBand[showBandCounter]; |
|
273 |
}catch(ArithmeticException exc){ |
|
274 |
average[showBandCounter] = 0; |
|
275 |
} |
|
276 |
|
|
277 |
//Calculo de mediana |
|
278 |
long middlePos = nPixelsBand[showBandCounter] >> 1; |
|
279 |
int aux = 0; |
|
280 |
int i = beginPos; |
|
281 |
for(i = beginPos; aux < middlePos; i++) |
|
282 |
aux += histogram[iBand][i]; |
|
283 |
middle[showBandCounter] = i - 1; |
|
284 |
|
|
285 |
showBandCounter ++; |
|
286 |
} |
|
287 |
} |
|
288 |
|
|
289 |
res[0] = min; |
|
290 |
res[1] = max; |
|
291 |
res[2] = average; |
|
292 |
res[3] = middle; |
|
293 |
res[4] = nPixelsBand; |
|
294 |
return res; |
|
295 |
} |
|
185 | 296 |
} |
Also available in: Unified diff