Revision 11080
trunk/libraries/libRaster/src/org/gvsig/raster/util/Histogram.java | ||
---|---|---|
127 | 127 |
* @return |
128 | 128 |
*/ |
129 | 129 |
public long[][] getAccumulatedHistogram() { |
130 |
if(histogram != null){ |
|
130 |
if (histogram != null){
|
|
131 | 131 |
long[][] hist = new long[histogram.length][histogram[0].length]; |
132 | 132 |
for (int iBand = 0; iBand < hist.length; iBand++) { |
133 |
for (int j = 0; j < hist[iBand].length; j++) { |
|
134 |
if(j == 0) |
|
135 |
hist[iBand][j] = histogram[iBand][j]; |
|
136 |
else |
|
137 |
hist[iBand][j] += histogram[iBand][j - 1]; |
|
133 |
hist[iBand][0] = histogram[iBand][0]; |
|
134 |
for (int j = 1; j < hist[iBand].length; j++) { |
|
135 |
hist[iBand][j] = hist[iBand][j - 1] + histogram[iBand][j]; |
|
138 | 136 |
} |
139 | 137 |
} |
138 |
return hist; |
|
140 | 139 |
} |
141 | 140 |
return null; |
142 | 141 |
} |
143 | 142 |
|
144 | 143 |
/** |
145 |
* Devuelve el histograma acumulado
|
|
144 |
* Devuelve el histograma logaritmico
|
|
146 | 145 |
* @return |
147 | 146 |
*/ |
148 | 147 |
public long[][] getLogaritmicHistogram() { |
149 |
//TODO: FUNCIONALIDAD: Falta el calculo del histograma logaritmico |
|
150 |
return histogram; |
|
148 |
if (histogram != null) { |
|
149 |
long[][] hist = new long[histogram.length][histogram[0].length]; |
|
150 |
long min = histogram[0][0]; |
|
151 |
for (int iBand = 0; iBand < histogram.length; iBand++) |
|
152 |
for (int j = 1; j < histogram[iBand].length; j++) |
|
153 |
if (min > histogram[iBand][j]) min = histogram[iBand][j]; |
|
154 |
for (int iBand = 0; iBand < histogram.length; iBand++) { |
|
155 |
for (int j = 0; j < histogram[iBand].length; j++) |
|
156 |
// Lo multiplico por 1000 para que no se pierdan datos al redondear |
|
157 |
hist[iBand][j] = (long) (1000.0 * java.lang.Math.log((double) (histogram[iBand][j] - min + 1))); |
|
158 |
} |
|
159 |
return hist; |
|
160 |
} |
|
161 |
return null; |
|
151 | 162 |
} |
152 | 163 |
|
153 | 164 |
/** |
154 | 165 |
* N?mero de tipos de histograma definidos en esta clase. |
155 | 166 |
* @return entero con el n?mero de tipos definidos. |
156 | 167 |
*/ |
157 |
public static int getHistogramTypesCount(){ |
|
168 |
public static int getHistogramTypesCount() {
|
|
158 | 169 |
return types.length; |
159 | 170 |
} |
160 | 171 |
|
... | ... | |
163 | 174 |
* @param pos posici?n en el array del tipo a obtener |
164 | 175 |
* @return Tipo |
165 | 176 |
*/ |
166 |
public static String getType(int pos){ |
|
177 |
public static String getType(int pos) {
|
|
167 | 178 |
return types[pos]; |
168 | 179 |
} |
169 | 180 |
|
... | ... | |
183 | 194 |
return null; |
184 | 195 |
} |
185 | 196 |
|
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[][] getBasicStats(boolean[] bands){ |
|
203 |
if(histogram == null) |
|
204 |
return null; |
|
205 |
return getBasicStats(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[][] getBasicStats(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 |
} |
|
197 |
/** |
|
198 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
199 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
200 |
* |
|
201 |
* <UL> |
|
202 |
* <LI>m?nimo</LI> |
|
203 |
* <LI>m?ximo</LI> |
|
204 |
* <LI>media</LI> |
|
205 |
* <LI>mediana</LI> |
|
206 |
* <LI>N?mero de pixels</LI> |
|
207 |
* </UL> |
|
208 |
* @param histogram |
|
209 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
210 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
211 |
* @return |
|
212 |
*/ |
|
213 |
public long[][] getBasicStats(boolean[] bands) { |
|
214 |
if(histogram == null) |
|
215 |
return null; |
|
216 |
return getBasicStats(0, histogram[0].length - 1, bands); |
|
217 |
} |
|
218 |
|
|
219 |
/** |
|
220 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
221 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
222 |
* |
|
223 |
* <UL> |
|
224 |
* <LI>m?nimo</LI> |
|
225 |
* <LI>m?ximo</LI> |
|
226 |
* <LI>media</LI> |
|
227 |
* <LI>mediana</LI> |
|
228 |
* <LI>N?mero de pixels</LI> |
|
229 |
* </UL> |
|
230 |
* @param histogram |
|
231 |
* @param beginPos Posici?n de inicio del histograma para contabilizar estadisticas |
|
232 |
* @param endPos Posici?n de fin del histograma para contabilizar estadisticas |
|
233 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
234 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
235 |
* @return |
|
236 |
*/ |
|
237 |
public long[][] getBasicStats(int beginPos, int endPos, boolean[] bands){ |
|
238 |
if(histogram == null) |
|
239 |
return null; |
|
240 |
|
|
241 |
//Contamos el n?mero de bandas para las cuales se calcula la estad?stica |
|
242 |
int bandCount = 0; |
|
243 |
for(int iBand = 0; iBand < bands.length; iBand ++) |
|
244 |
if(bands[iBand]) |
|
245 |
bandCount ++; |
|
246 |
|
|
247 |
int values = 5; |
|
248 |
long[][] res = new long[values][]; |
|
249 |
|
|
250 |
long[] min = new long[bandCount];//M?nimo |
|
251 |
long[] max = new long[bandCount];//M?ximo |
|
252 |
for(int iBand = 0; iBand < bandCount; iBand ++){ |
|
253 |
max[iBand] = beginPos; |
|
254 |
min[iBand] = endPos; |
|
255 |
} |
|
256 |
long[] average = new long[bandCount]; //Valor de pixel medio (Media) |
|
257 |
long[] middle = new long[bandCount]; //Mediana |
|
258 |
long[] nPixelsBand = new long[bandCount];//N?mero de pixels por banda |
|
259 |
|
|
260 |
int showBandCounter = 0; //Contador de bandas de las que hay calcular la estadistica |
|
261 |
for(int iBand = 0; iBand < histogram.length; iBand ++){ |
|
262 |
if(bands[iBand]){ |
|
263 |
int pixels = 0; //N?mero de valores por banda (entre 0 y 255) |
|
264 |
for(int i = beginPos; i <= endPos; i ++){ |
|
276 | 265 |
|
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; |
|
266 |
//Calculo del m?nimo |
|
267 |
if(histogram[iBand][i] != 0 && i < min[showBandCounter]) |
|
268 |
min[showBandCounter] = i; |
|
284 | 269 |
|
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 |
} |
|
296 |
} |
|
270 |
//Calculo del m?ximo |
|
271 |
if(histogram[iBand][i] != 0 && i > max[showBandCounter]) |
|
272 |
max[showBandCounter] = i; |
|
273 |
|
|
274 |
//Calculo del n?mero de pixeles |
|
275 |
nPixelsBand[showBandCounter] += (long)histogram[iBand][i]; |
|
276 |
|
|
277 |
if(histogram[iBand][i] != 0) |
|
278 |
pixels ++; |
|
279 |
|
|
280 |
average[showBandCounter] += histogram[iBand][i] * i; |
|
281 |
} |
|
282 |
//Calculo de la media |
|
283 |
try{ |
|
284 |
average[showBandCounter] /= nPixelsBand[showBandCounter]; |
|
285 |
}catch(ArithmeticException exc){ |
|
286 |
average[showBandCounter] = 0; |
|
287 |
} |
|
288 |
|
|
289 |
//Calculo de mediana |
|
290 |
long middlePos = nPixelsBand[showBandCounter] >> 1; |
|
291 |
int aux = 0; |
|
292 |
int i = beginPos; |
|
293 |
for(i = beginPos; aux < middlePos; i++) |
|
294 |
aux += histogram[iBand][i]; |
|
295 |
middle[showBandCounter] = i - 1; |
|
296 |
|
|
297 |
showBandCounter ++; |
|
298 |
} |
|
299 |
} |
|
300 |
|
|
301 |
res[0] = min; |
|
302 |
res[1] = max; |
|
303 |
res[2] = average; |
|
304 |
res[3] = middle; |
|
305 |
res[4] = nPixelsBand; |
|
306 |
return res; |
|
307 |
} |
|
308 |
} |
Also available in: Unified diff