Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / correction / MedianByteFilter.java @ 27361

History | View | Annotate | Download (2.75 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 java.util.Arrays;
22

    
23
import org.gvsig.raster.buffer.RasterBuffer;
24
import org.gvsig.raster.dataset.IBuffer;
25
/**
26
 * Filtro de Mediana que se aplica en la imagen. Toma como entrada la imagen y
27
 * el lado de la ventana de filtrado.
28
 *
29
 * @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
30
 */
31
public class MedianByteFilter extends MedianFilter {
32
        private int[] window = null;
33

    
34
        public MedianByteFilter() {
35
                super();
36
        }
37

    
38
        /*
39
         * (non-Javadoc)
40
         * @see org.gvsig.raster.grid.filter.correction.MedianFilter#pre()
41
         */
42
        public void pre() {
43
                super.pre();
44
                window = new int[sizeWindow];
45
                rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
46
        }
47

    
48
        /*
49
         * (non-Javadoc)
50
         * @see org.gvsig.raster.grid.filter.correction.MedianFilter#process(int, int)
51
         */
52
        public void process(int col, int line) throws InterruptedException {
53
                // Obtener el vector con la ventanas de muestras
54
                for (int band = 0; band < raster.getBandCount(); band++) {
55
                        int k = 0;
56
                        for (int i = -halfSide; i <= halfSide; i++)
57
                                for (int j = -halfSide; j <= halfSide; j++) {
58
                                        if ((col + i >= 0) && (line + j >= 0) && (col + i < width) && (line + j < height)) {
59
                                                window[k] = raster.getElemByte(line + j, col + i, band) & 0xff;
60
                                                k++;
61
                                        }
62
                                }
63
                        // Ordenar los valores de las ventanas, se supone que usa quickSort.
64
                        Arrays.sort(window, 0, k);
65

    
66
                        // Extraer los elementos centrales y asignarselos al pixel (x,y)
67
                        rasterResult.setElem(line, col, band, (byte) window[k >> 1]);
68
                }
69
        }
70

    
71
        /*
72
         * (non-Javadoc)
73
         * @see org.gvsig.raster.grid.filter.correction.MedianFilter#getInRasterDataType()
74
         */
75
        public int getInRasterDataType() {
76
                return RasterBuffer.TYPE_BYTE;
77
        }
78

    
79
        /*
80
         * (non-Javadoc)
81
         * @see org.gvsig.raster.grid.filter.RasterFilter#getOutRasterDataType()
82
         */
83
        public int getOutRasterDataType() {
84
                return RasterBuffer.TYPE_BYTE;
85
        }
86
}