Revision 11070
trunk/libraries/libRaster/src/org/gvsig/raster/util/Histogram.java | ||
---|---|---|
22 | 22 |
* Representa un histograma. |
23 | 23 |
* @version 27/03/2007 |
24 | 24 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
25 |
* |
|
26 | 25 |
*/ |
27 | 26 |
public class Histogram { |
28 | 27 |
private long[][] histogram = null; |
... | ... | |
126 | 125 |
* Devuelve el histograma acumulado |
127 | 126 |
* @return |
128 | 127 |
*/ |
129 |
|
|
130 | 128 |
public long[][] getAccumulatedHistogram() { |
131 | 129 |
if (histogram != null){ |
132 | 130 |
long[][] hist = new long[histogram.length][histogram[0].length]; |
... | ... | |
148 | 146 |
public long[][] getLogaritmicHistogram() { |
149 | 147 |
if (histogram != null) { |
150 | 148 |
long[][] hist = new long[histogram.length][histogram[0].length]; |
151 |
for (int iBand = 0; iBand < histogram.length; iBand++) {
|
|
152 |
long min = histogram[iBand][0];
|
|
149 |
long min = histogram[0][0];
|
|
150 |
for (int iBand = 0; iBand < histogram.length; iBand++)
|
|
153 | 151 |
for (int j = 1; j < histogram[iBand].length; j++) |
154 | 152 |
if (min > histogram[iBand][j]) min = histogram[iBand][j]; |
153 |
for (int iBand = 0; iBand < histogram.length; iBand++) { |
|
155 | 154 |
for (int j = 0; j < histogram[iBand].length; j++) |
156 | 155 |
// Lo multiplico por 1000 para que no se pierdan datos al redondear |
157 | 156 |
hist[iBand][j] = (long) (java.lang.Math.log((double) (histogram[iBand][j] - min + 1))*1000); |
... | ... | |
165 | 164 |
* N?mero de tipos de histograma definidos en esta clase. |
166 | 165 |
* @return entero con el n?mero de tipos definidos. |
167 | 166 |
*/ |
168 |
public static int getHistogramTypesCount(){ |
|
167 |
public static int getHistogramTypesCount() {
|
|
169 | 168 |
return types.length; |
170 | 169 |
} |
171 | 170 |
|
... | ... | |
174 | 173 |
* @param pos posici?n en el array del tipo a obtener |
175 | 174 |
* @return Tipo |
176 | 175 |
*/ |
177 |
public static String getType(int pos){ |
|
176 |
public static String getType(int pos) {
|
|
178 | 177 |
return types[pos]; |
179 | 178 |
} |
180 | 179 |
|
... | ... | |
194 | 193 |
return null; |
195 | 194 |
} |
196 | 195 |
|
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 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
220 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
221 |
* |
|
222 |
* <UL> |
|
223 |
* <LI>m?nimo</LI> |
|
224 |
* <LI>m?ximo</LI> |
|
225 |
* <LI>media</LI> |
|
226 |
* <LI>mediana</LI> |
|
227 |
* <LI>N?mero de pixels</LI> |
|
228 |
* </UL> |
|
229 |
* @param histogram |
|
230 |
* @param beginPos Posici?n de inicio del histograma para contabilizar estadisticas |
|
231 |
* @param endPos Posici?n de fin del histograma para contabilizar estadisticas |
|
232 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
233 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
234 |
* @return |
|
235 |
*/ |
|
236 |
public long[][] getBasicStats(int beginPos, int endPos, boolean[] bands){ |
|
237 |
if(histogram == null) |
|
238 |
return null; |
|
239 |
|
|
240 |
//Contamos el n?mero de bandas para las cuales se calcula la estad?stica |
|
241 |
int bandCount = 0; |
|
242 |
for(int iBand = 0; iBand < bands.length; iBand ++) |
|
243 |
if(bands[iBand]) |
|
244 |
bandCount ++; |
|
245 |
|
|
246 |
int values = 5; |
|
247 |
long[][] res = new long[values][]; |
|
248 |
|
|
249 |
long[] min = new long[bandCount];//M?nimo |
|
250 |
long[] max = new long[bandCount];//M?ximo |
|
251 |
for(int iBand = 0; iBand < bandCount; iBand ++){ |
|
252 |
max[iBand] = beginPos; |
|
253 |
min[iBand] = endPos; |
|
254 |
} |
|
255 |
long[] average = new long[bandCount]; //Valor de pixel medio (Media) |
|
256 |
long[] middle = new long[bandCount]; //Mediana |
|
257 |
long[] nPixelsBand = new long[bandCount];//N?mero de pixels por banda |
|
258 |
|
|
259 |
int showBandCounter = 0; //Contador de bandas de las que hay calcular la estadistica |
|
260 |
for(int iBand = 0; iBand < histogram.length; iBand ++){ |
|
261 |
if(bands[iBand]){ |
|
262 |
int pixels = 0; //N?mero de valores por banda (entre 0 y 255) |
|
263 |
for(int i = beginPos; i <= endPos; i ++){ |
|
264 |
|
|
265 |
//Calculo del m?nimo |
|
266 |
if(histogram[iBand][i] != 0 && i < min[showBandCounter]) |
|
267 |
min[showBandCounter] = i; |
|
268 |
|
|
269 |
//Calculo del m?ximo |
|
270 |
if(histogram[iBand][i] != 0 && i > max[showBandCounter]) |
|
271 |
max[showBandCounter] = i; |
|
272 |
|
|
273 |
//Calculo del n?mero de pixeles |
|
274 |
nPixelsBand[showBandCounter] += (long)histogram[iBand][i]; |
|
275 |
|
|
276 |
if(histogram[iBand][i] != 0) |
|
277 |
pixels ++; |
|
278 |
|
|
279 |
average[showBandCounter] += histogram[iBand][i] * i; |
|
280 |
} |
|
281 |
//Calculo de la media |
|
282 |
try{ |
|
283 |
average[showBandCounter] /= nPixelsBand[showBandCounter]; |
|
284 |
}catch(ArithmeticException exc){ |
|
285 |
average[showBandCounter] = 0; |
|
286 |
} |
|
196 |
/** |
|
197 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
198 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
199 |
* |
|
200 |
* <UL> |
|
201 |
* <LI>m?nimo</LI> |
|
202 |
* <LI>m?ximo</LI> |
|
203 |
* <LI>media</LI> |
|
204 |
* <LI>mediana</LI> |
|
205 |
* <LI>N?mero de pixels</LI> |
|
206 |
* </UL> |
|
207 |
* @param histogram |
|
208 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
209 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
210 |
* @return |
|
211 |
*/ |
|
212 |
public long[][] getBasicStats(boolean[] bands) { |
|
213 |
if(histogram == null) |
|
214 |
return null; |
|
215 |
return getBasicStats(0, histogram[0].length - 1, bands); |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Calculo de estad?sticas a partir de un histograma. El resultado de la funci?n es un array |
|
220 |
* bidimensional donde el primer ?ndice inndica la estadistica y el segundo el n?mero de banda. |
|
221 |
* |
|
222 |
* <UL> |
|
223 |
* <LI>m?nimo</LI> |
|
224 |
* <LI>m?ximo</LI> |
|
225 |
* <LI>media</LI> |
|
226 |
* <LI>mediana</LI> |
|
227 |
* <LI>N?mero de pixels</LI> |
|
228 |
* </UL> |
|
229 |
* @param histogram |
|
230 |
* @param beginPos Posici?n de inicio del histograma para contabilizar estadisticas |
|
231 |
* @param endPos Posici?n de fin del histograma para contabilizar estadisticas |
|
232 |
* @param bandas solicitadas. Cada elemento del vector representa una banda. Si est? a true se calcula la |
|
233 |
* estadistica para esa banda y si est? a false no se calcular?. |
|
234 |
* @return |
|
235 |
*/ |
|
236 |
public long[][] getBasicStats(int beginPos, int endPos, boolean[] bands){ |
|
237 |
if(histogram == null) |
|
238 |
return null; |
|
239 |
|
|
240 |
//Contamos el n?mero de bandas para las cuales se calcula la estad?stica |
|
241 |
int bandCount = 0; |
|
242 |
for(int iBand = 0; iBand < bands.length; iBand ++) |
|
243 |
if(bands[iBand]) |
|
244 |
bandCount ++; |
|
245 |
|
|
246 |
int values = 5; |
|
247 |
long[][] res = new long[values][]; |
|
248 |
|
|
249 |
long[] min = new long[bandCount];//M?nimo |
|
250 |
long[] max = new long[bandCount];//M?ximo |
|
251 |
for(int iBand = 0; iBand < bandCount; iBand ++){ |
|
252 |
max[iBand] = beginPos; |
|
253 |
min[iBand] = endPos; |
|
254 |
} |
|
255 |
long[] average = new long[bandCount]; //Valor de pixel medio (Media) |
|
256 |
long[] middle = new long[bandCount]; //Mediana |
|
257 |
long[] nPixelsBand = new long[bandCount];//N?mero de pixels por banda |
|
258 |
|
|
259 |
int showBandCounter = 0; //Contador de bandas de las que hay calcular la estadistica |
|
260 |
for(int iBand = 0; iBand < histogram.length; iBand ++){ |
|
261 |
if(bands[iBand]){ |
|
262 |
int pixels = 0; //N?mero de valores por banda (entre 0 y 255) |
|
263 |
for(int i = beginPos; i <= endPos; i ++){ |
|
287 | 264 |
|
288 |
//Calculo de mediana |
|
289 |
long middlePos = nPixelsBand[showBandCounter] >> 1; |
|
290 |
int aux = 0; |
|
291 |
int i = beginPos; |
|
292 |
for(i = beginPos; aux < middlePos; i++) |
|
293 |
aux += histogram[iBand][i]; |
|
294 |
middle[showBandCounter] = i - 1; |
|
265 |
//Calculo del m?nimo |
|
266 |
if(histogram[iBand][i] != 0 && i < min[showBandCounter]) |
|
267 |
min[showBandCounter] = i; |
|
295 | 268 |
|
296 |
showBandCounter ++; |
|
297 |
} |
|
298 |
} |
|
299 |
|
|
300 |
res[0] = min; |
|
301 |
res[1] = max; |
|
302 |
res[2] = average; |
|
303 |
res[3] = middle; |
|
304 |
res[4] = nPixelsBand; |
|
305 |
return res; |
|
306 |
} |
|
307 |
} |
|
269 |
//Calculo del m?ximo |
|
270 |
if(histogram[iBand][i] != 0 && i > max[showBandCounter]) |
|
271 |
max[showBandCounter] = i; |
|
272 |
|
|
273 |
//Calculo del n?mero de pixeles |
|
274 |
nPixelsBand[showBandCounter] += (long)histogram[iBand][i]; |
|
275 |
|
|
276 |
if(histogram[iBand][i] != 0) |
|
277 |
pixels ++; |
|
278 |
|
|
279 |
average[showBandCounter] += histogram[iBand][i] * i; |
|
280 |
} |
|
281 |
//Calculo de la media |
|
282 |
try{ |
|
283 |
average[showBandCounter] /= nPixelsBand[showBandCounter]; |
|
284 |
}catch(ArithmeticException exc){ |
|
285 |
average[showBandCounter] = 0; |
|
286 |
} |
|
287 |
|
|
288 |
//Calculo de mediana |
|
289 |
long middlePos = nPixelsBand[showBandCounter] >> 1; |
|
290 |
int aux = 0; |
|
291 |
int i = beginPos; |
|
292 |
for(i = beginPos; aux < middlePos; i++) |
|
293 |
aux += histogram[iBand][i]; |
|
294 |
middle[showBandCounter] = i - 1; |
|
295 |
|
|
296 |
showBandCounter ++; |
|
297 |
} |
|
298 |
} |
|
299 |
|
|
300 |
res[0] = min; |
|
301 |
res[1] = max; |
|
302 |
res[2] = average; |
|
303 |
res[3] = middle; |
|
304 |
res[4] = nPixelsBand; |
|
305 |
return res; |
|
306 |
} |
|
307 |
} |
trunk/libraries/libUIComponent/src-test/org/gvsig/gui/beans/graphic/TestGraphic.java | ||
---|---|---|
1 | 1 |
package org.gvsig.gui.beans.graphic; |
2 | 2 |
|
3 |
import java.awt.BorderLayout; |
|
4 |
|
|
3 | 5 |
import javax.swing.JFrame; |
4 | 6 |
|
7 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
|
8 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
|
5 | 9 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
10 |
import org.jfree.data.xy.XYSeries; |
|
11 |
import org.jfree.data.xy.XYSeriesCollection; |
|
6 | 12 |
|
7 | 13 |
public class TestGraphic implements GraphicListener { |
8 | 14 |
private JFrame frame=new JFrame(); |
15 |
private DefaultButtonsPanel defaultButtonsPanel = null; |
|
9 | 16 |
private GraphicContainer graphic = null; |
10 | 17 |
|
11 | 18 |
public TestGraphic() throws NotInitializeException{ |
12 | 19 |
graphic = new GraphicContainer(true); |
20 |
|
|
21 |
|
|
22 |
int nSeries = 3; |
|
23 |
|
|
24 |
String[] names = new String[nSeries]; |
|
25 |
int[][] series = new int[nSeries][256]; |
|
26 |
|
|
27 |
for(int iSerie = 0; iSerie < nSeries; iSerie++){ |
|
28 |
names[iSerie] = "Band " + iSerie; |
|
29 |
for (int i = 0; i < 256; i++) |
|
30 |
series[iSerie][i] = i * (iSerie + 1); |
|
31 |
} |
|
32 |
graphic.getPGraphic().setNewChart(series, names); |
|
33 |
|
|
34 |
|
|
13 | 35 |
graphic.addValueChangedListener(this); |
14 |
frame.getContentPane().add(graphic); |
|
15 |
frame.setSize(500, 300); |
|
36 |
defaultButtonsPanel = new DefaultButtonsPanel(ButtonsPanel.BUTTONS_CLOSE); |
|
37 |
defaultButtonsPanel.setLayout(new BorderLayout(5, 5)); |
|
38 |
defaultButtonsPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
|
39 |
defaultButtonsPanel.add(graphic, BorderLayout.CENTER); |
|
40 |
frame.getContentPane().add(defaultButtonsPanel); |
|
41 |
frame.setSize(640, 480); |
|
16 | 42 |
frame.show(); |
17 | 43 |
} |
18 | 44 |
|
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/GraphicChartPanel.java | ||
---|---|---|
34 | 34 |
import org.jfree.data.xy.XYSeriesCollection; |
35 | 35 |
|
36 | 36 |
/** |
37 |
* |
|
38 |
* Nacho Brodin (brodin_ign@gva.es) |
|
39 |
*/ |
|
40 |
|
|
41 |
public class GraphicChartPanel extends JPanel { |
|
37 |
* Componente gr?fico de JFree |
|
38 |
* |
|
39 |
* @version 05/04/2007 |
|
40 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
41 |
* @author Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
42 |
* |
|
43 |
*/public class GraphicChartPanel extends JPanel { |
|
42 | 44 |
private static final long serialVersionUID = 7328137487119964665L; |
43 | 45 |
private JFreeChart chart; |
44 | 46 |
private ChartPanel jPanelChart = null; |
... | ... | |
46 | 48 |
private XYSeriesCollection dataset = null; |
47 | 49 |
|
48 | 50 |
public GraphicChartPanel() { |
49 |
int nSeries = 3; |
|
50 |
|
|
51 |
series = new XYSeries[nSeries]; |
|
52 | 51 |
dataset = new XYSeriesCollection(); |
53 |
|
|
54 |
for(int iSerie = 0; iSerie < nSeries; iSerie++){ |
|
55 |
series[iSerie] = new XYSeries(""); |
|
56 |
for (int i = 0; i < 256; i++) |
|
57 |
series[iSerie].add(new Integer(i), new Integer(i * (iSerie + 1))); |
|
58 |
dataset.addSeries(series[iSerie]); |
|
59 |
} |
|
60 |
|
|
61 |
createChart(); |
|
52 |
|
|
53 |
createChart(); |
|
62 | 54 |
|
63 | 55 |
initialize(); |
64 | 56 |
|
65 | 57 |
Plot plot = this.jPanelChart.getChart().getPlot(); |
66 | 58 |
plot.setOutlineStroke(new BasicStroke(1)); |
67 |
plot.setOutlinePaint(Color.magenta); |
|
59 |
plot.setOutlinePaint(Color.black); |
|
60 |
|
|
61 |
chart.setBackgroundPaint(Color.white); |
|
62 |
plot.setBackgroundPaint(new Color(245, 245, 245)); |
|
68 | 63 |
} |
69 | 64 |
|
70 | 65 |
/** |
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/graphic/GraphicContainer.java | ||
---|---|---|
75 | 75 |
*/ |
76 | 76 |
private JPanel getPGeneral() { |
77 | 77 |
if (pGeneral == null) { |
78 |
GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
|
79 |
gridBagConstraints4.gridy = 2; |
|
80 |
gridBagConstraints4.insets = new java.awt.Insets(2,0,0,0); |
|
81 |
gridBagConstraints4.gridwidth = 0; |
|
82 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
|
83 |
gridBagConstraints3.gridy = 1; |
|
84 |
gridBagConstraints3.insets = new java.awt.Insets(2,0,0,0); |
|
85 |
gridBagConstraints3.gridx = 0; |
|
86 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
|
87 |
gridBagConstraints.gridy = 0; |
|
88 |
gridBagConstraints.insets = new java.awt.Insets(0,0,0,0); |
|
89 |
gridBagConstraints.gridx = 0; |
|
90 | 78 |
pGeneral = new JPanel(); |
91 | 79 |
pGeneral.setLayout(new BorderLayout(0, 2)); |
92 | 80 |
pGeneral.add(getPDoubleSlider(), BorderLayout.NORTH); |
... | ... | |
119 | 107 |
multiSlider.addValueChangedListener(this); |
120 | 108 |
panelSlider.setLayout(new BorderLayout()); |
121 | 109 |
panelSlider.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); |
122 |
// panelSlider.setBorder(javax.swing.BorderFactory.createEtchedBorder()); |
|
123 | 110 |
panelSlider.add(multiSlider, BorderLayout.CENTER); |
124 | 111 |
} |
125 | 112 |
return panelSlider; |
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramPanelListener.java | ||
---|---|---|
80 | 80 |
* por cada una. |
81 | 81 |
*/ |
82 | 82 |
private boolean[] showBands = null; |
83 |
|
|
83 | 84 |
private Color[] bandsColor = { |
84 | 85 |
Color.red, |
85 | 86 |
Color.green, |
... | ... | |
90 | 91 |
Color.gray, |
91 | 92 |
Color.magenta, |
92 | 93 |
Color.yellow, |
93 |
Color.orange, |
|
94 |
Color.pink, |
|
95 |
Color.lightGray}; |
|
94 |
Color.orange}; |
|
96 | 95 |
|
97 | 96 |
public HistogramPanelListener(HistogramPanel p){ |
98 | 97 |
histogramPanel = p; |
... | ... | |
316 | 315 |
|
317 | 316 |
for (int j=first; j<end; j++) |
318 | 317 |
newHistogram[numBand][j-first] = (int) auxHistogram[iBand][j]; |
319 |
bandNames[numBand] = iBand + "";
|
|
318 |
bandNames[numBand] = histogramPanel.getJComboBands().getItemAt(iBand + 1).toString();
|
|
320 | 319 |
|
321 | 320 |
histogramPanel.getGraphicContainer().setBandColor(numBand, bandsColor[iBand % bandsColor.length]); |
322 | 321 |
|
Also available in: Unified diff