Revision 9523 branches/piloto3d/libraries/libCq CMS for java.old/src/org/cresques/io/datastruct/Statistic.java
Statistic.java | ||
---|---|---|
34 | 34 |
/** |
35 | 35 |
* M?nimo valor de pixel por banda |
36 | 36 |
*/ |
37 |
public int[] minBandValue = {
|
|
38 |
Integer.MAX_VALUE, Integer.MAX_VALUE,
|
|
39 |
Integer.MAX_VALUE
|
|
37 |
public double[] minBandValue = {
|
|
38 |
Double.MAX_VALUE, Double.MAX_VALUE,
|
|
39 |
Double.MAX_VALUE
|
|
40 | 40 |
}; |
41 | 41 |
|
42 | 42 |
/** |
43 | 43 |
* M?ximo valor de pixel por banda |
44 | 44 |
*/ |
45 |
public int[] maxBandValue = {
|
|
46 |
Integer.MIN_VALUE, Integer.MIN_VALUE,
|
|
47 |
Integer.MIN_VALUE
|
|
45 |
public double[] maxBandValue = {
|
|
46 |
Double.MIN_VALUE, Double.MIN_VALUE,
|
|
47 |
Double.MIN_VALUE
|
|
48 | 48 |
}; |
49 | 49 |
|
50 | 50 |
/** |
51 | 51 |
* Segundo valor m?s peque?o de pixel por banda |
52 | 52 |
*/ |
53 |
public int[] secondMinBandValue = {
|
|
54 |
Integer.MAX_VALUE, Integer.MAX_VALUE,
|
|
55 |
Integer.MAX_VALUE
|
|
53 |
public double[] secondMinBandValue = {
|
|
54 |
Double.MAX_VALUE, Double.MAX_VALUE,
|
|
55 |
Double.MAX_VALUE
|
|
56 | 56 |
}; |
57 | 57 |
|
58 | 58 |
/** |
59 | 59 |
* Segundo valor m?s grande de pixel por banda |
60 | 60 |
*/ |
61 |
public int[] secondMaxBandValue = {
|
|
62 |
Integer.MIN_VALUE, Integer.MIN_VALUE,
|
|
63 |
Integer.MIN_VALUE
|
|
61 |
public double[] secondMaxBandValue = {
|
|
62 |
Double.MIN_VALUE, Double.MIN_VALUE,
|
|
63 |
Double.MIN_VALUE
|
|
64 | 64 |
}; |
65 | 65 |
|
66 | 66 |
/** |
... | ... | |
80 | 80 |
public Statistic() { |
81 | 81 |
super(); |
82 | 82 |
} |
83 |
|
|
84 |
public void pinta() { |
|
85 |
for (int i = 0; i < 3; i++) |
|
86 |
System.out.println(" Band [" + i + "]: " + minBandValue[i] + |
|
87 |
"..." + maxBandValue[i]); |
|
88 |
|
|
89 |
System.out.println("Porcentaje de recorte: " + tailPercent); |
|
83 |
|
|
84 |
/** |
|
85 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
86 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
87 |
* |
|
88 |
* <UL> |
|
89 |
* <LI>m?nimo</LI> |
|
90 |
* <LI>m?ximo</LI> |
|
91 |
* <LI>media</LI> |
|
92 |
* <LI>mediana</LI> |
|
93 |
* <LI>N?mero de pixels</LI> |
|
94 |
* </UL> |
|
95 |
* @param histogram |
|
96 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
97 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
98 |
* @return |
|
99 |
*/ |
|
100 |
public static long[][] getBasicStatsFromHistogram(int[][] histogram, boolean[] bands){ |
|
101 |
if(histogram == null) |
|
102 |
return null; |
|
103 |
return getBasicStatsFromHistogram(histogram, 0, histogram[0].length - 1, bands); |
|
90 | 104 |
} |
91 |
|
|
92 | 105 |
/** |
106 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
107 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
108 |
* |
|
109 |
* <UL> |
|
110 |
* <LI>m?nimo</LI> |
|
111 |
* <LI>m?ximo</LI> |
|
112 |
* <LI>media</LI> |
|
113 |
* <LI>mediana</LI> |
|
114 |
* <LI>N?mero de pixels</LI> |
|
115 |
* </UL> |
|
116 |
* @param histogram |
|
117 |
* @param beginPos Posici?n de inicio del histograma para contabilizar estadisticas |
|
118 |
* @param endPos Posici?n de fin del histograma para contabilizar estadisticas |
|
119 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
120 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
121 |
* @return |
|
122 |
*/ |
|
123 |
public static long[][] getBasicStatsFromHistogram(int[][] histogram, int beginPos, int endPos, boolean[] bands){ |
|
124 |
if(histogram == null) |
|
125 |
return null; |
|
126 |
|
|
127 |
//Contamos el n?mero de bandas para las cuales se calcula la estad?stica |
|
128 |
int bandCount = 0; |
|
129 |
for(int iBand = 0; iBand < bands.length; iBand ++) |
|
130 |
if(bands[iBand]) |
|
131 |
bandCount ++; |
|
132 |
|
|
133 |
int values = 5; |
|
134 |
long[][] res = new long[values][]; |
|
135 |
|
|
136 |
long[] min = new long[bandCount];//M?nimo |
|
137 |
long[] max = new long[bandCount];//M?ximo |
|
138 |
for(int iBand = 0; iBand < bandCount; iBand ++){ |
|
139 |
max[iBand] = beginPos; |
|
140 |
min[iBand] = endPos; |
|
141 |
} |
|
142 |
long[] average = new long[bandCount]; //Valor de pixel medio (Media) |
|
143 |
long[] middle = new long[bandCount]; //Mediana |
|
144 |
long[] nPixelsBand = new long[bandCount];//N?mero de pixels por banda |
|
145 |
|
|
146 |
int showBandCounter = 0; //Contador de bandas de las que hay calcular la estadistica |
|
147 |
for(int iBand = 0; iBand < histogram.length; iBand ++){ |
|
148 |
if(bands[iBand]){ |
|
149 |
int pixels = 0; //N?mero de valores por banda (entre 0 y 255) |
|
150 |
for(int i = beginPos; i <= endPos; i ++){ |
|
151 |
|
|
152 |
//Calculo del m?nimo |
|
153 |
if(histogram[iBand][i] != 0 && i < min[showBandCounter]) |
|
154 |
min[showBandCounter] = i; |
|
155 |
|
|
156 |
//Calculo del m?ximo |
|
157 |
if(histogram[iBand][i] != 0 && i > max[showBandCounter]) |
|
158 |
max[showBandCounter] = i; |
|
159 |
|
|
160 |
//Calculo del n?mero de pixeles |
|
161 |
nPixelsBand[showBandCounter] += (long)histogram[iBand][i]; |
|
162 |
|
|
163 |
if(histogram[iBand][i] != 0) |
|
164 |
pixels ++; |
|
165 |
|
|
166 |
average[showBandCounter] += histogram[iBand][i] * i; |
|
167 |
} |
|
168 |
//Calculo de la media |
|
169 |
try{ |
|
170 |
average[showBandCounter] /= nPixelsBand[showBandCounter]; |
|
171 |
}catch(ArithmeticException exc){ |
|
172 |
average[showBandCounter] = 0; |
|
173 |
} |
|
174 |
|
|
175 |
//Calculo de mediana |
|
176 |
long middlePos = nPixelsBand[showBandCounter] >> 1; |
|
177 |
int aux = 0; |
|
178 |
int i = 0; |
|
179 |
for(i = 0; aux < middlePos; i++) |
|
180 |
aux += histogram[iBand][i]; |
|
181 |
middle[showBandCounter] = i - 1; |
|
182 |
|
|
183 |
showBandCounter ++; |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
res[0] = min; |
|
188 |
res[1] = max; |
|
189 |
res[2] = average; |
|
190 |
res[3] = middle; |
|
191 |
res[4] = nPixelsBand; |
|
192 |
return res; |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
93 | 196 |
* Clase que contiene los valores calculados para una imagen. |
94 | 197 |
* Esto se usa cuando se solicita varias veces para una misma imagen solo |
95 | 198 |
* tenga que calcular los valores una vez. |
... | ... | |
97 | 200 |
*/ |
98 | 201 |
public class History { |
99 | 202 |
public String file = null; |
100 |
public int[] min = null;
|
|
101 |
public int[] max = null;
|
|
102 |
public int[] secMin = null;
|
|
103 |
public int[] secMax = null;
|
|
203 |
public double[] min = null;
|
|
204 |
public double[] max = null;
|
|
205 |
public double[] secMin = null;
|
|
206 |
public double[] secMax = null;
|
|
104 | 207 |
|
105 |
public History(String file, int[] min, int[] max, int[] secMin,
|
|
106 |
int[] secMax) {
|
|
208 |
public History(String file, double[] min, double[] max, double[] secMin,
|
|
209 |
double[] secMax) {
|
|
107 | 210 |
this.file = file; |
108 |
this.min = (int[]) min.clone();
|
|
109 |
this.max = (int[]) max.clone();
|
|
110 |
this.secMin = (int[]) secMin.clone();
|
|
111 |
this.secMax = (int[]) secMax.clone();
|
|
211 |
this.min = (double[]) min.clone();
|
|
212 |
this.max = (double[]) max.clone();
|
|
213 |
this.secMin = (double[]) secMin.clone();
|
|
214 |
this.secMax = (double[]) secMax.clone();
|
|
112 | 215 |
} |
113 | 216 |
} |
114 | 217 |
} |
Also available in: Unified diff