Revision 10894 trunk/libraries/libRaster/src/org/gvsig/raster/driver/datasetproperties/DatasetStatistics.java
DatasetStatistics.java | ||
---|---|---|
316 | 316 |
String s = new Double(percent).toString(); |
317 | 317 |
return tailTrim.get(s); |
318 | 318 |
} |
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 |
|
|
319 | 432 |
} |
Also available in: Unified diff