svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / buffer / TestGdalByteMultiBandHistogram.java @ 21610
History | View | Annotate | Download (5.97 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 junit.framework.TestCase; |
22 |
|
23 |
import org.gvsig.raster.RasterLibrary; |
24 |
import org.gvsig.raster.dataset.IRasterDataSource; |
25 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
26 |
import org.gvsig.raster.dataset.RasterDataset; |
27 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
28 |
import org.gvsig.raster.datastruct.Histogram; |
29 |
import org.gvsig.raster.datastruct.HistogramException; |
30 |
/**
|
31 |
* Test a un histograma de una imagen de 3 bandas de un byte por dato leido con gdal.
|
32 |
* El test comprueba valores a lo largo de todo el histograma
|
33 |
*
|
34 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
35 |
*/
|
36 |
public class TestGdalByteMultiBandHistogram extends TestCase{ |
37 |
private boolean printCode = false; |
38 |
private String baseDir = "./test-images/"; |
39 |
private String path1 = baseDir + "band1-30x28byte.tif"; |
40 |
private String path2 = baseDir + "band2-30x28byte.tif"; |
41 |
private String path3 = baseDir + "band3-30x28byte.tif"; |
42 |
|
43 |
public void start() { |
44 |
this.setUp();
|
45 |
this.testStack();
|
46 |
} |
47 |
|
48 |
public void setUp() { |
49 |
System.err.println("TestGdalByteMultiBandHistogram running..."); |
50 |
} |
51 |
|
52 |
static {
|
53 |
RasterLibrary.wakeUp(); |
54 |
} |
55 |
|
56 |
public void testStack() { |
57 |
try {
|
58 |
RasterDataset f1 = RasterDataset.open(null, path1);
|
59 |
RasterDataset f2 = RasterDataset.open(null, path2);
|
60 |
RasterDataset f3 = RasterDataset.open(null, path3);
|
61 |
|
62 |
BufferFactory ds = new BufferFactory(f1);
|
63 |
ds.addFile(f2); |
64 |
ds.addFile(f3); |
65 |
|
66 |
IRasterDataSource rmd = ds.getDataSource(); |
67 |
Histogram histogram = rmd.getHistogram(); |
68 |
histogram = Histogram.convertHistogramToRGB(histogram); |
69 |
|
70 |
if (printCode)
|
71 |
print(histogram); |
72 |
|
73 |
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, 5, 8, 4, 10, 6, 5, 5, 4, 1, 5, 2, 3, 3, 6, 3, 3, 3, 4, 1, 1, 2, 1, 3, 0, 2,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0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
78 |
for (int i = 0; i < band1.length; i++) |
79 |
assertEquals((int) histogram.getHistogramValue(1, i), band1[i]); |
80 |
|
81 |
int band2[] = { 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, 0, 0, 0, 0, 0, 4, 5, 6, 14, 31, 28, 32, 27, 23, 12, 10, 5, 3, 2, 5, 3, 1, 2, 1, 4, 0, 1, 1, 1, 2, 1, 1, 0, 1, 0, 1, 1, 0, 2, 0, 0, 0, 1, 1, 0, 1, 1, 1, 2, 1, 3, 1, 1, 1, 0, 0, 0, 3, 1, 0, 0, 1, 4, 2, 1, 2, 3, 3, 5, 3, 5, 1, 5, 4, 3, 3, 2, 3, 4, 5, 7, 9, 2, 3, 5, 4, 3, 6, 4, 4, 4, 6, 4, 8, 10, 9, 5, 13, 6, 7, 4, 4, 7, 8, 6, 10, 7, 6, 6, 11, 9, 8, 5, 6, 8, 14, 10, 12, 11, 7, 7, 5, 8, 7, 8, 11, 10, 7, 10, 8, 8, 3, 2, 4, 1, 5, 4, 5, 6, 8, 6, 7, 8, 4, 4, 4, 5, 3, 3, 5, 5, 1, 3, 5, 4, 3, 3, 1, 2, 1, 3, 0, 2, 2, 1, 2, 5, 3, 1, 0, 2, 0, 3, 0, 1, 1, 1, 2, 0, 2, 1, 0, 0, 0, 2, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 2 }; |
82 |
for (int i = 0; i < band2.length; i++) |
83 |
assertEquals((int) histogram.getHistogramValue(2, i), band2[i]); |
84 |
|
85 |
} catch (HistogramException e) {
|
86 |
e.printStackTrace(); |
87 |
} catch (NotSupportedExtensionException e) {
|
88 |
e.printStackTrace(); |
89 |
} catch (RasterDriverException e) {
|
90 |
e.printStackTrace(); |
91 |
} catch (InterruptedException e) { |
92 |
e.printStackTrace(); |
93 |
} |
94 |
} |
95 |
|
96 |
public void print(Histogram histogram) { |
97 |
for (int i = 0; i < histogram.getNumBands(); i++) { |
98 |
System.out.println(""); |
99 |
System.out.print("int band" + i + "[] = { "); |
100 |
for (int j = 0; j < histogram.getBandLenght(i); j++) { |
101 |
if (j != 0) |
102 |
System.out.print(", "); |
103 |
System.out.print(((int) histogram.getHistogramValue(i, j))); |
104 |
} |
105 |
System.out.println("};"); |
106 |
System.out.println("for (int i = 0; i < band" + i + ".length; i++)"); |
107 |
System.out.println(" assertEquals((int) histogram.getHistogramValue(" + i + ", i), band" + i + "[i]);"); |
108 |
} |
109 |
} |
110 |
} |