Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / correction / ModeDoubleFilter.java @ 2438

History | View | Annotate | Download (2.56 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.raster.impl.grid.filter.correction;
23

    
24
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
25
import org.gvsig.fmap.dal.coverage.exception.FilterAddException;
26

    
27
/**
28
 * Proceso que aplica el filtro de Moda a un raster de tipo double
29
 * 
30
 * 23/07/2008
31
 * @author Nacho Brodin nachobrodin@gmail.com
32
 */
33
public class ModeDoubleFilter extends ModeFilter {
34
        private double[]                   window = null;
35
        private double                     tempValue       = 0;
36

    
37
        public ModeDoubleFilter() {
38
                super();
39
        }
40

    
41
        public void pre() throws FilterAddException {
42
                super.pre();
43
                window = new double[sizeWindow];
44
        }
45

    
46
        public void process(int col, int line) {
47
                for (int band = 0; band < numberOfBandsToProcess(); band++) {
48
                        int k = 0;
49
                        count = 0;
50
                        for (int i = -halfSide; i <= halfSide; i++) {
51
                                for (int j = -halfSide; j <= halfSide; j++) {
52
                                        if ((col + i >= 0) && (line + j >= 0) && (col + i < width) && (line + j < height)) {
53
                                                window[k] = raster.getElemDouble(line + j, col + i, band);
54
                                                if(i == -halfSide && j == -halfSide) 
55
                                                        tempValue = window[k];
56
                                                if(tempValue == window[k])
57
                                                        count ++;
58
                                                k++;
59
                                        }
60
                                }
61
                        }
62

    
63
                        if(count > sizeWindow)
64
                                return;
65
                        
66
                        k = 1;
67
                        while(k < window.length) {
68
                                int auxCount = 0;
69
                                for (int i = k; i < window.length; i++) {
70
                                        if(window[i] == window[k])
71
                                                auxCount ++;
72
                                }
73
                                if(auxCount > count) {
74
                                        count = auxCount;
75
                                        tempValue = window[k];
76
                                        if(count > sizeWindow)
77
                                                return;
78
                                }
79
                                k++;
80
                        }
81
                        rasterResult.setElem(line, col, band, (double) tempValue);
82
                }
83
        }
84

    
85
        public int getInRasterDataType() {
86
                return Buffer.TYPE_DOUBLE;
87
        }
88

    
89
        public int getOutRasterDataType() {
90
                return Buffer.TYPE_DOUBLE;
91
        }
92
}