Revision 5482
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.api/src/main/java/org/gvsig/raster/lib/buffer/api/statistics/StatisticsBand.java | ||
---|---|---|
38 | 38 |
*/ |
39 | 39 |
public long getBandLenght(); |
40 | 40 |
|
41 |
|
|
41 | 42 |
/** |
43 |
* Obtiene el tipo de datos de la banda |
|
44 |
* |
|
45 |
* @return el tipo de datos de la banda |
|
46 |
*/ |
|
47 |
public int getDataType(); |
|
48 |
|
|
49 |
/** |
|
42 | 50 |
* Obtiene el valor del segundo m?ximo |
43 | 51 |
* |
44 | 52 |
* @return Valor del segundo m?ximo |
... | ... | |
64 | 72 |
* |
65 | 73 |
* @return minimum |
66 | 74 |
*/ |
67 |
public double getMinimun();
|
|
75 |
public double getMinimum();
|
|
68 | 76 |
|
69 | 77 |
/** |
70 | 78 |
* Obtiene el valor medio |
... | ... | |
121 | 129 |
* @throws ProcessInterruptedException |
122 | 130 |
*/ |
123 | 131 |
public void calculate(double scale, SimpleTaskStatus status); |
132 |
// |
|
133 |
// /** |
|
134 |
// * Gets the number of pixels by band |
|
135 |
// * |
|
136 |
// * @return the number of pixels by band |
|
137 |
// */ |
|
138 |
// public long getNumberOfCells(); |
|
124 | 139 |
|
125 | 140 |
/** |
126 |
* Gets the number of pixels by band |
|
127 |
* |
|
128 |
* @return the number of pixels by band |
|
129 |
*/ |
|
130 |
public long getNumberOfCells(); |
|
131 |
|
|
132 |
/** |
|
133 |
* Devuelve la matriz de varianza-covarianza, si no se encuentra calculada se calcula |
|
134 |
* |
|
135 |
* @return Matriz de varianza-covarianza |
|
136 |
*/ |
|
137 |
public double[] getVarianceCovarianceMatrix(); |
|
138 |
|
|
139 |
/** |
|
140 | 141 |
* Gets histogram of the band |
141 | 142 |
* |
142 | 143 |
* @return HistogramBand |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.api/src/main/java/org/gvsig/raster/lib/buffer/api/statistics/HistogramBand.java | ||
---|---|---|
84 | 84 |
// */ |
85 | 85 |
// public long[] getNegativeTable(); |
86 | 86 |
|
87 |
/** |
|
88 |
* Devuelve el minimo valor del histograma |
|
89 |
* |
|
90 |
* @return el minimo valor del histograma |
|
91 |
*/ |
|
92 |
public double getMinimum(); |
|
87 |
// /** |
|
88 |
// * Devuelve el minimo valor del histograma |
|
89 |
// * |
|
90 |
// * @return el minimo valor del histograma |
|
91 |
// */ |
|
92 |
// public double getMinimum(); |
|
93 |
// |
|
94 |
// /** |
|
95 |
// * Devuelve el maximo valor del histograma |
|
96 |
// * |
|
97 |
// * @return el maximo valor del histograma |
|
98 |
// */ |
|
99 |
// public double getMaximum(); |
|
93 | 100 |
|
94 | 101 |
/** |
95 |
* Devuelve el maximo valor del histograma |
|
96 |
* |
|
97 |
* @return el maximo valor del histograma |
|
98 |
*/ |
|
99 |
public double getMaximum(); |
|
100 |
|
|
101 |
/** |
|
102 | 102 |
* Obtiene el n?mero de valores o clases del histograma |
103 | 103 |
* @return entero que representa el n?mero de valores o clases del histograma |
104 | 104 |
*/ |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.api/src/main/java/org/gvsig/raster/lib/buffer/api/statistics/Statistics.java | ||
---|---|---|
162 | 162 |
*/ |
163 | 163 |
public double[][] getVarianceCovarianceMatrix(); |
164 | 164 |
|
165 |
/** |
|
166 |
* Return the histogram. |
|
167 |
* |
|
168 |
* @return Histogram |
|
169 |
*/ |
|
170 |
public Histogram getHistogram(); |
|
171 |
|
|
165 | 172 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.api/src/main/java/org/gvsig/raster/lib/buffer/api/statistics/Histogram.java | ||
---|---|---|
50 | 50 |
// */ |
51 | 51 |
// public boolean union(Histogram hist); |
52 | 52 |
|
53 |
/** |
|
54 |
* Obtiene la tabla de valores |
|
55 |
* |
|
56 |
* @return la tabla de valores |
|
57 |
*/ |
|
58 |
public long[][] getTable(); |
|
53 |
// /** |
|
54 |
// * Obtiene la tabla de valores |
|
55 |
// * |
|
56 |
// * @return la tabla de valores |
|
57 |
// */ |
|
58 |
// public long[][] getTable(); |
|
59 |
// |
|
60 |
// |
|
61 |
// /** |
|
62 |
// * Obtiene el histograma de la imagen negativa. |
|
63 |
// * |
|
64 |
// * @return el histograma de la imagen negativa. |
|
65 |
// */ |
|
66 |
// public long[][] getNegativeTable(); |
|
59 | 67 |
|
60 |
|
|
61 |
/** |
|
62 |
* Obtiene el histograma de la imagen negativa. |
|
63 |
* |
|
64 |
* @return el histograma de la imagen negativa. |
|
65 |
*/ |
|
66 |
public long[][] getNegativeTable(); |
|
67 |
|
|
68 | 68 |
// /** |
69 | 69 |
// * Devuelve el minimo valor del histograma |
70 | 70 |
// * |
... | ... | |
79 | 79 |
// */ |
80 | 80 |
// public double getMaximum(); |
81 | 81 |
|
82 |
/** |
|
83 |
* Obtiene el n?mero de valores o clases del histograma |
|
84 |
* @return entero que representa el n?mero de valores o clases del histograma |
|
85 |
*/ |
|
86 |
public int getNumValues(); |
|
82 |
// /** |
|
83 |
// * Obtiene el n?mero de valores o clases del histograma |
|
84 |
// * @return entero que representa el n?mero de valores o clases del histograma |
|
85 |
// */ |
|
86 |
// public int getNumValues(); |
|
87 |
// |
|
88 |
// /** |
|
89 |
// * Devuelve si un histograma esta en un rango RGB aceptable |
|
90 |
// * |
|
91 |
// * @return si un histograma esta en un rango RGB aceptable |
|
92 |
// */ |
|
93 |
// public boolean isInRangeRGB(); |
|
87 | 94 |
|
88 |
/** |
|
89 |
* Devuelve si un histograma esta en un rango RGB aceptable |
|
90 |
* |
|
91 |
* @return si un histograma esta en un rango RGB aceptable |
|
92 |
*/ |
|
93 |
public boolean isInRangeRGB(); |
|
94 |
|
|
95 | 95 |
// /** |
96 | 96 |
// * Calcula las estad?sticas. |
97 | 97 |
// * |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/VarianceOperation.java | ||
---|---|---|
1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
|
2 |
|
|
3 |
import org.gvsig.raster.lib.buffer.api.statistics.StatisticsBand; |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* @author fdiaz |
|
8 |
* |
|
9 |
*/ |
|
10 |
public class VarianceOperation implements StatisticalOperation { |
|
11 |
|
|
12 |
double sigma; |
|
13 |
double sigmaSquare; |
|
14 |
long n; |
|
15 |
double mean; |
|
16 |
double variance; |
|
17 |
|
|
18 |
/** |
|
19 |
* Arithmetic mean |
|
20 |
*/ |
|
21 |
public VarianceOperation() { |
|
22 |
sigma = 0; |
|
23 |
sigmaSquare = 0; |
|
24 |
n = 0; |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public void pre() { |
|
29 |
//do nothing |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public void addValue(Number value) { |
|
34 |
double doubleValue = value.doubleValue(); |
|
35 |
|
|
36 |
sigma += doubleValue; |
|
37 |
sigmaSquare += doubleValue*doubleValue; |
|
38 |
n++; |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public void post() { |
|
43 |
mean = sigma/n; |
|
44 |
variance = sigmaSquare/n - (mean*mean); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public Object getResult() { |
|
49 |
return variance; |
|
50 |
} |
|
51 |
|
|
52 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/HistogramOperation.java | ||
---|---|---|
1 | 1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.gvsig.raster.lib.buffer.api.Band; |
|
7 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
|
8 |
import org.gvsig.raster.lib.buffer.api.statistics.HistogramBand; |
|
9 |
import org.gvsig.raster.lib.buffer.api.statistics.HistogramClass; |
|
3 | 10 |
import org.gvsig.raster.lib.buffer.api.statistics.StatisticsBand; |
4 | 11 |
|
5 |
|
|
12 |
/** |
|
13 |
* @author fdiaz |
|
14 |
* |
|
15 |
*/ |
|
6 | 16 |
public class HistogramOperation implements StatisticalOperation { |
7 | 17 |
|
18 |
private StatisticsBand statisticsBand; |
|
19 |
private List<HistogramClass> histogramClasses; |
|
20 |
private HistogramBand histogramBand; |
|
21 |
private Band band; |
|
8 | 22 |
|
23 |
public HistogramOperation(StatisticsBand statisticsBand, Band band) { |
|
24 |
this.statisticsBand = statisticsBand; |
|
25 |
this.band = band; |
|
26 |
} |
|
9 | 27 |
|
10 | 28 |
@Override |
11 |
public void preOperation(StatisticsBand statisticsBand) { |
|
12 |
// TODO Auto-generated method stub |
|
29 |
public void pre() { |
|
30 |
int dataType = this.statisticsBand.getDataType(); |
|
31 |
if(dataType == BufferManager.TYPE_DOUBLE || dataType == BufferManager.TYPE_FLOAT){ |
|
32 |
calculateHistogramClasses(); |
|
33 |
histogramBand = new DefaultHistogramBand(band, this.histogramClasses); |
|
13 | 34 |
|
35 |
} else { |
|
36 |
histogramBand = new DefaultHistogramBand(band); |
|
37 |
} |
|
14 | 38 |
} |
15 | 39 |
|
16 |
@Override
|
|
17 |
public void executionOperation(Object value) {
|
|
18 |
// TODO Auto-generated method stub
|
|
40 |
private void calculateHistogramClasses() {
|
|
41 |
int classesNumber = new Double(Math.ceil(Math.sqrt(this.statisticsBand.getBandLenght()))).intValue();
|
|
42 |
histogramClasses = new ArrayList<HistogramClass>(classesNumber);
|
|
19 | 43 |
|
44 |
double range = this.statisticsBand.getMaximum()-this.statisticsBand.getMinimum(); |
|
45 |
double widthInterval = range/classesNumber; |
|
46 |
double minInterval = this.statisticsBand.getMinimum(); |
|
47 |
double maxInterval; // = this.statisticsBand.getMaximum(); |
|
48 |
for(int i=0; i<classesNumber-1; i++){ |
|
49 |
maxInterval = minInterval+widthInterval; |
|
50 |
DefaultHistogramClass histogramClass = new DefaultHistogramClass(minInterval, maxInterval); |
|
51 |
histogramClass.setValue(0); |
|
52 |
histogramClasses.add(histogramClass); |
|
53 |
minInterval = maxInterval; |
|
54 |
} |
|
55 |
DefaultHistogramClass histogramClass = new DefaultHistogramClass(minInterval, this.statisticsBand.getMaximum()); |
|
56 |
histogramClasses.add(histogramClass); |
|
57 |
|
|
20 | 58 |
} |
21 | 59 |
|
22 | 60 |
@Override |
23 |
public void postOperation(StatisticsBand statisticsBand) { |
|
24 |
// TODO Auto-generated method stub |
|
61 |
public void addValue(Number value) { |
|
62 |
((DefaultHistogramBand)histogramBand).addValue(value.doubleValue()); |
|
63 |
} |
|
25 | 64 |
|
65 |
@Override |
|
66 |
public void post() { |
|
67 |
// do nothing |
|
26 | 68 |
} |
27 | 69 |
|
28 | 70 |
@Override |
29 | 71 |
public Object getResult() { |
30 |
// TODO Auto-generated method stub |
|
31 |
return null; |
|
72 |
return histogramBand; |
|
32 | 73 |
} |
33 | 74 |
|
34 | 75 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/DefaultStatistics.java | ||
---|---|---|
1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import org.gvsig.raster.lib.buffer.api.Band; |
|
6 |
import org.gvsig.raster.lib.buffer.api.statistics.Histogram; |
|
7 |
import org.gvsig.raster.lib.buffer.api.statistics.HistogramBand; |
|
8 |
import org.gvsig.raster.lib.buffer.api.statistics.Statistics; |
|
9 |
import org.gvsig.raster.lib.buffer.api.statistics.StatisticsBand; |
|
10 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
11 |
|
|
12 |
|
|
13 |
/** |
|
14 |
* @author fdiaz |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class DefaultStatistics implements Statistics { |
|
18 |
|
|
19 |
StatisticsBand[] statisticsBands; |
|
20 |
List<Band> bands; |
|
21 |
|
|
22 |
/** |
|
23 |
* |
|
24 |
*/ |
|
25 |
public DefaultStatistics( List<Band> bands) { |
|
26 |
this.bands = bands; |
|
27 |
statisticsBands = new StatisticsBand[bands.size()]; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public long[] getNumberOfValues() { |
|
32 |
long[] result = new long[statisticsBands.length]; |
|
33 |
for (int i = 0; i < statisticsBands.length; i++) { |
|
34 |
result[i]= statisticsBands[i].getBandLenght(); |
|
35 |
} |
|
36 |
return result; |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public double[] getMax() { |
|
41 |
double[] result = new double[statisticsBands.length]; |
|
42 |
for (int i = 0; i < statisticsBands.length; i++) { |
|
43 |
result[i]= statisticsBands[i].getMaximum(); |
|
44 |
} |
|
45 |
return result; |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public double[] getSecondMax() { |
|
50 |
double[] result = new double[statisticsBands.length]; |
|
51 |
for (int i = 0; i < statisticsBands.length; i++) { |
|
52 |
result[i]= statisticsBands[i].getSecondMax(); |
|
53 |
} |
|
54 |
return result; |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public double[] getSecondMin() { |
|
59 |
double[] result = new double[statisticsBands.length]; |
|
60 |
for (int i = 0; i < statisticsBands.length; i++) { |
|
61 |
result[i]= statisticsBands[i].getSecondMin(); |
|
62 |
} |
|
63 |
return result; |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public double getMaximun() { |
|
68 |
double result = Double.NEGATIVE_INFINITY; |
|
69 |
for (int i = 0; i < statisticsBands.length; i++) { |
|
70 |
double max = statisticsBands[i].getMaximum(); |
|
71 |
if(result<max){ |
|
72 |
result = max; |
|
73 |
} |
|
74 |
} |
|
75 |
return result; |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public double getMinimun() { |
|
80 |
double result = Double.POSITIVE_INFINITY; |
|
81 |
for (int i = 0; i < statisticsBands.length; i++) { |
|
82 |
double min = statisticsBands[i].getMinimum(); |
|
83 |
if(result>min){ |
|
84 |
result = min; |
|
85 |
} |
|
86 |
} |
|
87 |
return result; |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public double[] getMean() { |
|
92 |
double[] result = new double[statisticsBands.length]; |
|
93 |
for (int i = 0; i < statisticsBands.length; i++) { |
|
94 |
result[i]= statisticsBands[i].getMean(); |
|
95 |
} |
|
96 |
return result; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public double[] getMin() { |
|
101 |
double[] result = new double[statisticsBands.length]; |
|
102 |
for (int i = 0; i < statisticsBands.length; i++) { |
|
103 |
result[i]= statisticsBands[i].getMinimum(); |
|
104 |
} |
|
105 |
return result; |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public double[] getVariance() { |
|
110 |
double[] result = new double[statisticsBands.length]; |
|
111 |
for (int i = 0; i < statisticsBands.length; i++) { |
|
112 |
result[i]= statisticsBands[i].getVariance(); |
|
113 |
} |
|
114 |
return result; |
|
115 |
} |
|
116 |
|
|
117 |
@Override |
|
118 |
public int getBandCount() { |
|
119 |
return statisticsBands.length; |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public Object getTailTrimValue(double percent) { |
|
124 |
// TODO Auto-generated method stub |
|
125 |
return null; |
|
126 |
} |
|
127 |
|
|
128 |
@Override |
|
129 |
public Object[] getTailTrimValue(int pos) { |
|
130 |
// TODO Auto-generated method stub |
|
131 |
return null; |
|
132 |
} |
|
133 |
|
|
134 |
@Override |
|
135 |
public int getTailTrimCount() { |
|
136 |
// TODO Auto-generated method stub |
|
137 |
return 0; |
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 |
public boolean isCalculated() { |
|
142 |
// TODO Auto-generated method stub |
|
143 |
return false; |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
public void calculate(double scale, SimpleTaskStatus status) { |
|
148 |
// TODO Auto-generated method stub |
|
149 |
|
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public long[] getNumberOfCells() { |
|
154 |
// TODO Auto-generated method stub |
|
155 |
return null; |
|
156 |
} |
|
157 |
|
|
158 |
@Override |
|
159 |
public double[][] getVarianceCovarianceMatrix() { |
|
160 |
// double dSum[][] = new double[statisticsBands.length][statisticsBands.length]; |
|
161 |
// double iValues[][] = new double[statisticsBands.length][statisticsBands.length]; |
|
162 |
// double[][] varCov = new double[statisticsBands.length][statisticsBands.length]; |
|
163 |
// |
|
164 |
// for (int iBand = 0; iBand < statisticsBands.length; iBand++) |
|
165 |
// for (int jBand = 0; jBand < statisticsBands.length; jBand++){ |
|
166 |
// dSum[iBand][jBand] = 0; |
|
167 |
// iValues[iBand][jBand] = 0; |
|
168 |
// } |
|
169 |
// |
|
170 |
// for (int i = 0; i < statisticsBands.length; i++) { |
|
171 |
// for (int j = i; j < statisticsBands.length; j++) { |
|
172 |
// valorBandai = valorBandai - mean[i]; |
|
173 |
// valorBandaj = valorBandaj - mean[j]; |
|
174 |
// dSum[i][j] += valorBandai*valorBandaj; |
|
175 |
// iValues[i][j]++; |
|
176 |
// } |
|
177 |
// } |
|
178 |
// } |
|
179 |
// } |
|
180 |
// } |
|
181 |
// |
|
182 |
// // Asigno el valor a la matriz |
|
183 |
// for (int iBand = 0; iBand < statisticsBands.length; iBand++) |
|
184 |
// for (int jBand = 0; jBand < statisticsBands.length; jBand++) |
|
185 |
// if (iValues[iBand][jBand] > 1) |
|
186 |
// varCov[iBand][jBand] = dSum[iBand][jBand] / (double)(iValues[iBand][jBand]); |
|
187 |
// else |
|
188 |
// varCov[iBand][jBand] = roi.getStore().getNoDataValue().getValue().doubleValue(); |
|
189 |
// |
|
190 |
// // Completar parte simetrica de la matriz |
|
191 |
// for (int i = 0; i < statisticsBands.length; i++) { |
|
192 |
// for (int j = 0; j < statisticsBands.length; j++) { |
|
193 |
// if(j < i) |
|
194 |
// varCov[i][j] = varCov[j][i]; |
|
195 |
// } |
|
196 |
// } |
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
// TODO Auto-generated method stub |
|
201 |
return null; |
|
202 |
} |
|
203 |
|
|
204 |
@Override |
|
205 |
public Histogram getHistogram() { |
|
206 |
HistogramBand[] histogramBands = new HistogramBand[statisticsBands.length]; |
|
207 |
for (int i = 0; i < statisticsBands.length; i++) { |
|
208 |
histogramBands[i]= statisticsBands[i].getHistogramBand(); |
|
209 |
} |
|
210 |
Histogram histogram = new DefaultHistogram(histogramBands); |
|
211 |
return histogram; |
|
212 |
} |
|
213 |
|
|
214 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/SecondMinOperation.java | ||
---|---|---|
1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
|
2 |
|
|
3 |
/** |
|
4 |
* @author fdiaz |
|
5 |
* |
|
6 |
*/ |
|
7 |
public class SecondMinOperation implements StatisticalOperation { |
|
8 |
|
|
9 |
double min; |
|
10 |
double secondMin; |
|
11 |
|
|
12 |
/** |
|
13 |
* Arithmetic mean |
|
14 |
*/ |
|
15 |
public SecondMinOperation() { |
|
16 |
min = Double.POSITIVE_INFINITY; |
|
17 |
secondMin = Double.POSITIVE_INFINITY; |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
public void pre() { |
|
22 |
// do nothing |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public void addValue(Number value) { |
|
27 |
if (value.doubleValue() < min) { |
|
28 |
secondMin = min; |
|
29 |
min = value.doubleValue(); |
|
30 |
} |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
public void post() { |
|
35 |
// do nothing |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Object getResult() { |
|
40 |
return secondMin; |
|
41 |
} |
|
42 |
|
|
43 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/MeanOperation.java | ||
---|---|---|
1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
|
2 |
|
|
3 |
import org.gvsig.raster.lib.buffer.api.statistics.StatisticsBand; |
|
4 |
|
|
5 |
/** |
|
6 |
* @author fdiaz |
|
7 |
* |
|
8 |
*/ |
|
9 |
public class MeanOperation implements StatisticalOperation { |
|
10 |
|
|
11 |
double sigma; |
|
12 |
long n; |
|
13 |
double mean; |
|
14 |
|
|
15 |
/** |
|
16 |
* Arithmetic mean |
|
17 |
*/ |
|
18 |
public MeanOperation() { |
|
19 |
sigma = 0; |
|
20 |
n = 0; |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
public void pre() { |
|
25 |
// do nothing |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
public void addValue(Number value) { |
|
30 |
sigma += value.doubleValue(); |
|
31 |
n++; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public void post() { |
|
36 |
mean = sigma / n; |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public Object getResult() { |
|
41 |
return mean; |
|
42 |
} |
|
43 |
|
|
44 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/DefaultHistogram.java | ||
---|---|---|
1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
|
2 |
|
|
3 |
import java.util.Iterator; |
|
4 |
|
|
5 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
|
6 |
import org.gvsig.raster.lib.buffer.api.statistics.Histogram; |
|
7 |
import org.gvsig.raster.lib.buffer.api.statistics.HistogramBand; |
|
8 |
|
|
9 |
|
|
10 |
/** |
|
11 |
* @author fdiaz |
|
12 |
* |
|
13 |
*/ |
|
14 |
public class DefaultHistogram implements Histogram { |
|
15 |
|
|
16 |
|
|
17 |
private HistogramBand[] histogramBands; |
|
18 |
|
|
19 |
/** |
|
20 |
* @param histogramBands |
|
21 |
*/ |
|
22 |
public DefaultHistogram(HistogramBand[] histogramBands) { |
|
23 |
this.histogramBands = histogramBands; |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public Iterator<HistogramBand> iterator() { |
|
28 |
|
|
29 |
|
|
30 |
// TODO Auto-generated method stub |
|
31 |
return null; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public int size() { |
|
36 |
return histogramBands.length; |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public HistogramBand get(int band) { |
|
41 |
return histogramBands[band]; |
|
42 |
} |
|
43 |
|
|
44 |
// @Override |
|
45 |
// public long[][] getTable() { |
|
46 |
// table = new long[histogramBands.length][] |
|
47 |
// // TODO Auto-generated method stub |
|
48 |
// return null; |
|
49 |
// } |
|
50 |
// |
|
51 |
// @Override |
|
52 |
// public long[][] getNegativeTable() { |
|
53 |
// // TODO Auto-generated method stub |
|
54 |
// return null; |
|
55 |
// } |
|
56 |
|
|
57 |
// @Override |
|
58 |
// public int getNumValues() { |
|
59 |
// // TODO Auto-generated method stub |
|
60 |
// return 0; |
|
61 |
// } |
|
62 |
// |
|
63 |
// @Override |
|
64 |
// public boolean isInRangeRGB() { |
|
65 |
// // TODO Auto-generated method stub |
|
66 |
// return false; |
|
67 |
// } |
|
68 |
|
|
69 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/SecondMaxOperation.java | ||
---|---|---|
1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
|
2 |
|
|
3 |
/** |
|
4 |
* @author fdiaz |
|
5 |
* |
|
6 |
*/ |
|
7 |
public class SecondMaxOperation implements StatisticalOperation { |
|
8 |
|
|
9 |
double max; |
|
10 |
double secondMax; |
|
11 |
|
|
12 |
/** |
|
13 |
* Arithmetic mean |
|
14 |
*/ |
|
15 |
public SecondMaxOperation() { |
|
16 |
max = Double.NEGATIVE_INFINITY; |
|
17 |
secondMax = Double.NEGATIVE_INFINITY; |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
public void pre() { |
|
22 |
// do nothing |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public void addValue(Number value) { |
|
27 |
if (value.doubleValue() > max) { |
|
28 |
secondMax = max; |
|
29 |
max = value.doubleValue(); |
|
30 |
} |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
public void post() { |
|
35 |
// do nothing |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Object getResult() { |
|
40 |
return secondMax; |
|
41 |
} |
|
42 |
|
|
43 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/DefaultStatisticsBand.java | ||
---|---|---|
5 | 5 |
import org.gvsig.raster.lib.buffer.api.statistics.StatisticsBand; |
6 | 6 |
import org.gvsig.tools.task.SimpleTaskStatus; |
7 | 7 |
|
8 |
/** |
|
9 |
* @author fdiaz |
|
10 |
* |
|
11 |
*/ |
|
8 | 12 |
public class DefaultStatisticsBand implements StatisticsBand{ |
9 | 13 |
|
10 | 14 |
Band band; |
11 | 15 |
|
12 |
long bandLength; |
|
13 |
double secondMax; |
|
14 | 16 |
boolean calculated; |
15 |
//TODO el resto de datos |
|
16 | 17 |
|
18 |
private double mean; |
|
19 |
private double max; |
|
20 |
private double secondMax; |
|
21 |
private double min; |
|
22 |
private double secondMin; |
|
23 |
private double variance; |
|
24 |
private HistogramBand histogramBand; |
|
17 | 25 |
|
26 |
|
|
27 |
/** |
|
28 |
* @param band |
|
29 |
*/ |
|
18 | 30 |
public DefaultStatisticsBand(Band band) { |
19 | 31 |
this.band=band; |
20 | 32 |
this.calculated=false; |
... | ... | |
28 | 40 |
|
29 | 41 |
@Override |
30 | 42 |
public void calculate(double scale, SimpleTaskStatus status) { |
43 |
calculated = false; |
|
31 | 44 |
|
45 |
MeanOperation meanOperation = new MeanOperation(); |
|
46 |
MaxOperation maxOperation = new MaxOperation(); |
|
47 |
MinOperation minOperation = new MinOperation(); |
|
48 |
SecondMaxOperation secondMaxOperation = new SecondMaxOperation(); |
|
49 |
SecondMinOperation secondMinOperation = new SecondMinOperation(); |
|
50 |
VarianceOperation varianceOperation = new VarianceOperation(); |
|
51 |
//TODO: CovarianceOperation |
|
32 | 52 |
|
53 |
meanOperation.pre(); |
|
54 |
maxOperation.pre(); |
|
55 |
minOperation.pre(); |
|
56 |
secondMaxOperation.pre(); |
|
57 |
secondMinOperation.pre(); |
|
58 |
varianceOperation.pre(); |
|
33 | 59 |
|
60 |
for(int row=0; row<band.getRows(); row++){ |
|
61 |
for(int column=0; column<band.getColumns(); column++){ |
|
62 |
Object obj = band.get(row, column); |
|
63 |
if(obj instanceof Number){ |
|
64 |
double value = ((Number)obj).doubleValue(); |
|
65 |
meanOperation.addValue(value); |
|
66 |
maxOperation.addValue(value); |
|
67 |
minOperation.addValue(value); |
|
68 |
secondMaxOperation.addValue(value); |
|
69 |
secondMinOperation.addValue(value); |
|
70 |
varianceOperation.addValue(value); |
|
71 |
} |
|
72 |
} |
|
73 |
} |
|
74 |
meanOperation.post(); |
|
75 |
maxOperation.post(); |
|
76 |
minOperation.post(); |
|
77 |
secondMaxOperation.post(); |
|
78 |
secondMinOperation.post(); |
|
79 |
varianceOperation.post(); |
|
80 |
|
|
81 |
this.mean = ((Number)meanOperation.getResult()).doubleValue(); |
|
82 |
this.max = ((Number)maxOperation.getResult()).doubleValue(); |
|
83 |
this.min = ((Number)minOperation.getResult()).doubleValue(); |
|
84 |
this.secondMax = ((Number)secondMaxOperation.getResult()).doubleValue(); |
|
85 |
this.secondMin = ((Number)secondMinOperation.getResult()).doubleValue(); |
|
86 |
this.variance = ((Number)varianceOperation.getResult()).doubleValue(); |
|
87 |
HistogramOperation histogramOperation = new HistogramOperation(this, this.band); |
|
88 |
histogramOperation.pre(); |
|
89 |
for(int row=0; row<band.getRows(); row++){ |
|
90 |
for(int column=0; column<band.getColumns(); column++){ |
|
91 |
Object obj = band.get(row, column); |
|
92 |
if(obj instanceof Number){ |
|
93 |
double value = ((Number)obj).doubleValue(); |
|
94 |
histogramOperation.addValue(value); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
histogramOperation.post(); |
|
99 |
this.histogramBand = ((HistogramBand)histogramOperation.getResult()); |
|
100 |
|
|
34 | 101 |
status.terminate(); |
35 | 102 |
calculated=true; |
36 | 103 |
} |
37 | 104 |
|
38 | 105 |
@Override |
106 |
public int getDataType() { |
|
107 |
return this.band.getDataType(); |
|
108 |
} |
|
109 |
|
|
110 |
@Override |
|
39 | 111 |
public long getBandLenght() { |
40 |
// TODO Auto-generated method stub |
|
41 |
return 0; |
|
112 |
return band.getRows()*band.getColumns(); |
|
42 | 113 |
} |
43 | 114 |
|
44 | 115 |
@Override |
45 | 116 |
public double getSecondMax() { |
46 |
// TODO Auto-generated method stub
|
|
47 |
return 0;
|
|
117 |
//TODO ??? y si no est? calculado???
|
|
118 |
return this.secondMax;
|
|
48 | 119 |
} |
49 | 120 |
|
50 | 121 |
@Override |
51 | 122 |
public double getSecondMin() { |
52 |
// TODO Auto-generated method stub |
|
53 |
return 0; |
|
123 |
return this.secondMin; |
|
54 | 124 |
} |
55 | 125 |
|
56 | 126 |
@Override |
57 | 127 |
public double getMaximum() { |
58 |
// TODO Auto-generated method stub |
|
59 |
return 0; |
|
128 |
return this.max; |
|
60 | 129 |
} |
61 | 130 |
|
62 | 131 |
@Override |
63 |
public double getMinimun() { |
|
64 |
// TODO Auto-generated method stub |
|
65 |
return 0; |
|
132 |
public double getMinimum() { |
|
133 |
return this.min; |
|
66 | 134 |
} |
67 | 135 |
|
68 | 136 |
@Override |
69 | 137 |
public double getMean() { |
70 |
// TODO Auto-generated method stub |
|
71 |
return 0; |
|
138 |
return this.mean; |
|
72 | 139 |
} |
73 | 140 |
|
74 | 141 |
@Override |
75 | 142 |
public double getVariance() { |
76 |
// TODO Auto-generated method stub |
|
77 |
return 0; |
|
143 |
return this.variance; |
|
78 | 144 |
} |
79 | 145 |
|
80 | 146 |
@Override |
... | ... | |
95 | 161 |
return 0; |
96 | 162 |
} |
97 | 163 |
|
98 |
@Override |
|
99 |
public long getNumberOfCells() { |
|
100 |
// TODO Auto-generated method stub |
|
101 |
return 0; |
|
102 |
} |
|
164 |
// @Override
|
|
165 |
// public long getNumberOfCells() {
|
|
166 |
// // TODO Auto-generated method stub
|
|
167 |
// return 0;
|
|
168 |
// }
|
|
103 | 169 |
|
104 | 170 |
@Override |
105 |
public double[] getVarianceCovarianceMatrix() { |
|
106 |
// TODO Auto-generated method stub |
|
107 |
return null; |
|
171 |
public HistogramBand getHistogramBand() { |
|
172 |
return this.histogramBand; |
|
108 | 173 |
} |
109 | 174 |
|
110 | 175 |
|
111 |
@Override |
|
112 |
public HistogramBand getHistogramBand() { |
|
113 |
// TODO Auto-generated method stub |
|
114 |
return null; |
|
115 |
} |
|
116 | 176 |
|
117 | 177 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/MinOperation.java | ||
---|---|---|
1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
|
2 |
|
|
3 |
|
|
4 |
/** |
|
5 |
* @author fdiaz |
|
6 |
* |
|
7 |
*/ |
|
8 |
public class MinOperation implements StatisticalOperation { |
|
9 |
|
|
10 |
double min; |
|
11 |
|
|
12 |
/** |
|
13 |
* Arithmetic mean |
|
14 |
*/ |
|
15 |
public MinOperation() { |
|
16 |
min = Double.POSITIVE_INFINITY; |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
public void pre() { |
|
21 |
// do nothing |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
public void addValue(Number value) { |
|
26 |
if (value.doubleValue() < min) { |
|
27 |
min = value.doubleValue(); |
|
28 |
} |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public void post() { |
|
33 |
// do nothing |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public Object getResult() { |
|
38 |
return min; |
|
39 |
} |
|
40 |
|
|
41 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/StatisticalOperation.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
/** |
13 | 13 |
* Operations done before processing |
14 |
* @param statisticsBand |
|
15 | 14 |
*/ |
16 |
public void preOperation(StatisticsBand statisticsBand);
|
|
15 |
public void pre();
|
|
17 | 16 |
|
18 | 17 |
/** |
19 | 18 |
* Operations done during processing |
20 | 19 |
* @param value |
21 | 20 |
*/ |
22 |
public void executionOperation(Object value);
|
|
21 |
public void addValue(Number value);
|
|
23 | 22 |
|
24 | 23 |
/** |
25 | 24 |
* Operations done after processing |
26 |
* @param statisticsBand |
|
27 | 25 |
*/ |
28 |
public void postOperation(StatisticsBand statisticsBand);
|
|
26 |
public void post();
|
|
29 | 27 |
|
30 | 28 |
/** |
31 | 29 |
* Gets the results after processing. |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/MaxOperation.java | ||
---|---|---|
1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
|
2 |
|
|
3 |
import org.gvsig.raster.lib.buffer.api.statistics.StatisticsBand; |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* @author fdiaz |
|
8 |
* |
|
9 |
*/ |
|
10 |
public class MaxOperation implements StatisticalOperation { |
|
11 |
|
|
12 |
double max; |
|
13 |
|
|
14 |
/** |
|
15 |
* Arithmetic mean |
|
16 |
*/ |
|
17 |
public MaxOperation() { |
|
18 |
max = Double.NEGATIVE_INFINITY; |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
public void pre() { |
|
23 |
//do nothing |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public void addValue(Number value) { |
|
28 |
if(value.doubleValue() > max){ |
|
29 |
max = value.doubleValue(); |
|
30 |
} |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
public void post() { |
|
35 |
//do nothing |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Object getResult() { |
|
40 |
return max; |
|
41 |
} |
|
42 |
|
|
43 |
} |
org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/DefaultHistogramBand.java | ||
---|---|---|
1 | 1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
2 | 2 |
|
3 | 3 |
import java.util.ArrayList; |
4 |
import java.util.Collections; |
|
4 | 5 |
import java.util.List; |
5 | 6 |
|
6 | 7 |
import org.gvsig.raster.lib.buffer.api.Band; |
7 | 8 |
import org.gvsig.raster.lib.buffer.api.statistics.HistogramBand; |
8 | 9 |
import org.gvsig.raster.lib.buffer.api.statistics.HistogramClass; |
9 |
import org.gvsig.tools.task.SimpleTaskStatus; |
|
10 | 10 |
|
11 | 11 |
|
12 |
/** |
|
13 |
* @author fdiaz |
|
14 |
* |
|
15 |
*/ |
|
12 | 16 |
public class DefaultHistogramBand implements HistogramBand { |
13 | 17 |
|
14 | 18 |
Band band; |
15 | 19 |
List<HistogramClass> histogramClasses; |
16 |
double max; |
|
17 |
double min; |
|
18 | 20 |
|
21 |
|
|
19 | 22 |
public DefaultHistogramBand(Band band){ |
20 | 23 |
this.band=band; |
21 | 24 |
this.histogramClasses=new ArrayList<HistogramClass>(); |
22 | 25 |
} |
23 | 26 |
|
27 |
public DefaultHistogramBand(Band band, List<HistogramClass> histogramClasses){ |
|
28 |
this.band=band; |
|
29 |
this.histogramClasses=histogramClasses; |
|
30 |
Collections.sort(this.histogramClasses); |
|
31 |
} |
|
32 |
|
|
24 | 33 |
@Override |
25 | 34 |
public int getBandLenght() { |
26 | 35 |
return this.band.getRows()*this.band.getColumns(); |
... | ... | |
78 | 87 |
} |
79 | 88 |
return frequencies; |
80 | 89 |
} |
90 |
// |
|
91 |
// @Override |
|
92 |
// public double getMinimum() { |
|
93 |
// return min; |
|
94 |
// } |
|
95 |
// |
|
96 |
// @Override |
|
97 |
// public double getMaximum() { |
|
98 |
// return max; |
|
99 |
// } |
|
81 | 100 |
|
82 | 101 |
@Override |
83 |
public double getMinimum() { |
|
84 |
return min; |
|
85 |
} |
|
86 |
|
|
87 |
@Override |
|
88 |
public double getMaximum() { |
|
89 |
return max; |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 | 102 |
public int getNumValues() { |
94 | 103 |
return histogramClasses.size(); |
95 | 104 |
} |
... | ... | |
135 | 144 |
return 0; |
136 | 145 |
} |
137 | 146 |
|
147 |
public void addValue(double value){ |
|
148 |
HistogramClass histogramClass = getHistogramClass(value); |
|
149 |
if(histogramClass == null){ |
|
150 |
histogramClass = new DefaultHistogramClass(value, value); |
|
151 |
histogramClass.setValue(1); |
|
152 |
histogramClasses.add(histogramClass); |
|
153 |
Collections.sort(histogramClasses); |
|
154 |
} else { |
|
155 |
histogramClass.increment(1); |
|
156 |
} |
|
157 |
} |
|
138 | 158 |
|
139 | 159 |
} |
Also available in: Unified diff