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 / ModeByteFilter.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 byte
29
 * 
30
 * @author Nacho Brodin nachobrodin@gmail.com
31
 */
32
public class ModeByteFilter extends ModeFilter {
33
        private int[]                   window = null;
34
        private int                     tempValue       = 0;
35

    
36
        public ModeByteFilter() {
37
                super();
38
        }
39

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

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

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

    
86
        public int getInRasterDataType() {
87
                return Buffer.TYPE_BYTE;
88
        }
89

    
90
        public int getOutRasterDataType() {
91
                return Buffer.TYPE_BYTE;
92
        }
93
}