Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.main / src / test / java / org / gvsig / fmap / dal / coverage / buffer / TestGdalByteHistogram.java @ 2443

History | View | Annotate | Download (4.11 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer;
23

    
24
import org.gvsig.fmap.dal.coverage.BaseTestCase;
25
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram;
26
import org.gvsig.fmap.dal.coverage.exception.HistogramException;
27
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
31
import org.gvsig.raster.impl.datastruct.BufferHistogramImpl;
32
/**
33
 * Test a un histograma de una imagen de 3 bandas de un byte por dato leido con gdal. 
34
 * El test comprueba valores a lo largo de todo el histograma
35
 * 
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class TestGdalByteHistogram extends BaseTestCase {
39
        private String path = baseDir + "histograma.bmp";        
40
        private RasterDataStore       f              = null;        
41
        
42
    public void start() throws Exception {
43
                this.setUp();
44
                this.testStack();
45
        }
46
        
47
    @Override
48
    protected void doSetUp() throws Exception {
49
                System.err.println("TestGdalByteHistogram running...");
50
                try {
51
                        super.doSetUp();
52
                } catch (Exception e) {
53
                        e.printStackTrace();
54
                }
55
        }
56

    
57
        public void testStack() {
58
                try {
59
                        f = manager.open(path);
60
                } catch (NotSupportedExtensionException e) {
61
                        return;
62
                } catch (RasterDriverException e) {
63
                        e.printStackTrace();
64
                }
65
//                ds = new BufferFactory(f);
66
                BufferHistogram histogram = null;
67
                try {
68
                        histogram = ((RasterDataStore)f).getHistogramComputer().getBufferHistogram();
69
                        histogram = BufferHistogramImpl.convertHistogramToRGB(histogram);
70
                } catch (ProcessInterruptedException e) {
71
                        e.printStackTrace();
72
                } catch (HistogramException e) {
73
                        e.printStackTrace();
74
                }
75
                //print(histogram);
76
                resultTest(histogram);
77
        }
78
        
79
        private void resultTest(BufferHistogram histogram) {
80
                for (int i = 0; i <= 255; i++) {
81
                        switch (i) {
82
                                case 0:
83
                                        assertEquals((int) histogram.getHistogramValue(0, i), 1);
84
                                        break;
85
                                case 1:
86
                                        assertEquals((int) histogram.getHistogramValue(0, i), 2);
87
                                        break;
88
                                case 2:
89
                                        assertEquals((int) histogram.getHistogramValue(0, i), 3);
90
                                        break;
91
                                case 126:
92
                                        assertEquals((int) histogram.getHistogramValue(0, i), 4);
93
                                        break;
94
                                case 127:
95
                                        assertEquals((int) histogram.getHistogramValue(0, i), 5);
96
                                        break;
97
                                case 128:
98
                                        assertEquals((int) histogram.getHistogramValue(0, i), 6);
99
                                        break;
100
                                case 129:
101
                                        assertEquals((int) histogram.getHistogramValue(0, i), 7);
102
                                        break;
103
                                case 253:
104
                                        assertEquals((int) histogram.getHistogramValue(0, i), 8);
105
                                        break;
106
                                case 254:
107
                                        assertEquals((int) histogram.getHistogramValue(0, i), 9);
108
                                        break;
109
                                case 255:
110
                                        assertEquals((int) histogram.getHistogramValue(0, i), 10);
111
                                        break;
112
                                default:
113
                                        assertEquals((int) histogram.getHistogramValue(0, i), 0);
114
                                        break;
115
                        }
116
                }
117
        }
118

    
119
        public void print(BufferHistogram histogram) {
120
                for (int i = 0; i < histogram.getNumBands(); i++) {
121
                        int cont = 0;
122
                        for (int j = 0; j < histogram.getBandLenght(i); j++) {
123
                                double var = histogram.getHistogramValue(i, j);
124
                                if (var != 0) {
125
                                        System.out.println(j + ": " + var);
126
                                        cont += var;
127
                                }
128
                        }
129
                        System.out.println("");
130
                        System.out.println(cont + " ");
131
                }
132
        }
133
}