root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / correction / ModeDoubleFilter.java @ 27361
History | View | Annotate | Download (2.85 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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.grid.filter.correction; |
20 |
|
21 |
import org.gvsig.raster.buffer.RasterBuffer; |
22 |
|
23 |
/**
|
24 |
* Proceso que aplica el filtro de Moda a un raster de tipo double
|
25 |
*
|
26 |
* 23/07/2008
|
27 |
* @author Nacho Brodin nachobrodin@gmail.com
|
28 |
*/
|
29 |
public class ModeDoubleFilter extends ModeFilter { |
30 |
private double[] window = null; |
31 |
private double tempValue = 0; |
32 |
|
33 |
public ModeDoubleFilter() {
|
34 |
super();
|
35 |
} |
36 |
|
37 |
/*
|
38 |
* (non-Javadoc)
|
39 |
* @see org.gvsig.raster.grid.filter.correction.MedianFilter#pre()
|
40 |
*/
|
41 |
public void pre() { |
42 |
super.pre();
|
43 |
window = new double[sizeWindow]; |
44 |
} |
45 |
|
46 |
/*
|
47 |
* (non-Javadoc)
|
48 |
* @see org.gvsig.raster.grid.filter.correction.MedianFilter#process(int, int)
|
49 |
*/
|
50 |
public void process(int col, int line) throws InterruptedException { |
51 |
for (int band = 0; band < raster.getBandCount(); band++) { |
52 |
int k = 0; |
53 |
count = 0;
|
54 |
for (int i = -halfSide; i <= halfSide; i++) { |
55 |
for (int j = -halfSide; j <= halfSide; j++) { |
56 |
if ((col + i >= 0) && (line + j >= 0) && (col + i < width) && (line + j < height)) { |
57 |
window[k] = raster.getElemDouble(line + j, col + i, band); |
58 |
if(i == -halfSide && j == -halfSide)
|
59 |
tempValue = window[k]; |
60 |
if(tempValue == window[k])
|
61 |
count ++; |
62 |
k++; |
63 |
} |
64 |
} |
65 |
} |
66 |
|
67 |
if(count > sizeWindow)
|
68 |
return;
|
69 |
|
70 |
k = 1;
|
71 |
while(k < window.length) {
|
72 |
int auxCount = 0; |
73 |
for (int i = k; i < window.length; i++) { |
74 |
if(window[i] == window[k])
|
75 |
auxCount ++; |
76 |
} |
77 |
if(auxCount > count) {
|
78 |
count = auxCount; |
79 |
tempValue = window[k]; |
80 |
if(count > sizeWindow)
|
81 |
return;
|
82 |
} |
83 |
k++; |
84 |
} |
85 |
rasterResult.setElem(line, col, band, (double) tempValue);
|
86 |
} |
87 |
} |
88 |
|
89 |
/*
|
90 |
* (non-Javadoc)
|
91 |
* @see org.gvsig.raster.grid.filter.correction.MedianFilter#getInRasterDataType()
|
92 |
*/
|
93 |
public int getInRasterDataType() { |
94 |
return RasterBuffer.TYPE_DOUBLE;
|
95 |
} |
96 |
|
97 |
/*
|
98 |
* (non-Javadoc)
|
99 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getOutRasterDataType()
|
100 |
*/
|
101 |
public int getOutRasterDataType() { |
102 |
return RasterBuffer.TYPE_DOUBLE;
|
103 |
} |
104 |
} |