root / branches / v2_0_0_prep / libraries / libRaster / src-test / org / gvsig / raster / buffer / TestGdalByteMultiBandHistogram.java @ 30754
History | View | Annotate | Download (6.09 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.buffer; |
20 |
|
21 |
import org.gvsig.raster.BaseTestCase; |
22 |
import org.gvsig.raster.RasterLibrary; |
23 |
import org.gvsig.raster.dataset.IRasterDataSource; |
24 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
25 |
import org.gvsig.raster.dataset.RasterDataset; |
26 |
import org.gvsig.raster.dataset.RasterDriverException; |
27 |
import org.gvsig.raster.datastruct.Histogram; |
28 |
import org.gvsig.raster.datastruct.HistogramException; |
29 |
/**
|
30 |
* Test a un histograma de una imagen de 3 bandas de un byte por dato leido con gdal.
|
31 |
* El test comprueba valores a lo largo de todo el histograma
|
32 |
*
|
33 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
34 |
*/
|
35 |
public class TestGdalByteMultiBandHistogram extends BaseTestCase { |
36 |
private boolean printCode = false; |
37 |
private String baseDir = "./test-images/"; |
38 |
private String path1 = baseDir + "band1-30x28byte.tif"; |
39 |
private String path2 = baseDir + "band2-30x28byte.tif"; |
40 |
private String path3 = baseDir + "band3-30x28byte.tif"; |
41 |
|
42 |
public void start() throws Exception { |
43 |
this.setUp();
|
44 |
this.testStack();
|
45 |
} |
46 |
|
47 |
protected void doSetUp() throws Exception { |
48 |
super.doSetUp();
|
49 |
System.err.println("TestGdalByteMultiBandHistogram running..."); |
50 |
} |
51 |
|
52 |
static {
|
53 |
RasterLibrary.wakeUp(); |
54 |
} |
55 |
|
56 |
public void testStack() { |
57 |
try {
|
58 |
deleteRMF(path1); |
59 |
deleteRMF(path2); |
60 |
deleteRMF(path3); |
61 |
RasterDataset f1 = RasterDataset.open(null, path1);
|
62 |
RasterDataset f2 = RasterDataset.open(null, path2);
|
63 |
RasterDataset f3 = RasterDataset.open(null, path3);
|
64 |
|
65 |
BufferFactory ds = new BufferFactory(f1);
|
66 |
ds.addFile(f2); |
67 |
ds.addFile(f3); |
68 |
|
69 |
IRasterDataSource rmd = ds.getDataSource(); |
70 |
Histogram histogram = rmd.getHistogram(); |
71 |
histogram = Histogram.convertHistogramToRGB(histogram); |
72 |
|
73 |
if (printCode)
|
74 |
print(histogram); |
75 |
|
76 |
int band0[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 9, 12, 23, 33, 32, 29, 17, 29, 11, 9, 9, 8, 3, 3, 3, 1, 1, 0, 1, 6, 4, 5, 3, 2, 7, 6, 10, 8, 12, 12, 4, 5, 16, 13, 11, 13, 13, 13, 21, 20, 16, 27, 14, 14, 21, 23, 20, 20, 15, 17, 12, 9, 20, 15, 7, 11, 5, 10, 6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int i = 0; i < band2.length; i++) |
86 |
assertEquals((int) histogram.getHistogramValue(2, i), band2[i]); |
87 |
|
88 |
} catch (HistogramException e) {
|
89 |
e.printStackTrace(); |
90 |
} catch (NotSupportedExtensionException e) {
|
91 |
e.printStackTrace(); |
92 |
} catch (RasterDriverException e) {
|
93 |
e.printStackTrace(); |
94 |
} catch (InterruptedException e) { |
95 |
e.printStackTrace(); |
96 |
} |
97 |
} |
98 |
|
99 |
public void print(Histogram histogram) { |
100 |
for (int i = 0; i < histogram.getNumBands(); i++) { |
101 |
System.out.println(""); |
102 |
System.out.print("int band" + i + "[] = { "); |
103 |
for (int j = 0; j < histogram.getBandLenght(i); j++) { |
104 |
if (j != 0) |
105 |
System.out.print(", "); |
106 |
System.out.print(((int) histogram.getHistogramValue(i, j))); |
107 |
} |
108 |
System.out.println("};"); |
109 |
System.out.println("for (int i = 0; i < band" + i + ".length; i++)"); |
110 |
System.out.println(" assertEquals((int) histogram.getHistogramValue(" + i + ", i), band" + i + "[i]);"); |
111 |
} |
112 |
} |
113 |
} |