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 / MedianIntegerFilter.java @ 2443
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 java.util.Arrays; |
25 |
|
26 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
27 |
import org.gvsig.fmap.dal.coverage.exception.FilterAddException; |
28 |
import org.gvsig.raster.impl.DefaultRasterManager; |
29 |
import org.gvsig.raster.impl.buffer.RasterBuffer; |
30 |
/**
|
31 |
* Filtro de Mediana que se aplica en la imagen. Toma como entrada la imagen y
|
32 |
* el lado de la ventana de filtrado.
|
33 |
*
|
34 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
35 |
*/
|
36 |
public class MedianIntegerFilter extends MedianFilter { |
37 |
private int[] window = null; |
38 |
|
39 |
public MedianIntegerFilter() {
|
40 |
super();
|
41 |
} |
42 |
|
43 |
public void pre() throws FilterAddException { |
44 |
super.pre();
|
45 |
window = new int[sizeWindow]; |
46 |
rasterResult = DefaultRasterManager.getInstance().createBuffer(Buffer.TYPE_INT, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true); |
47 |
} |
48 |
|
49 |
public void process(int col, int line) { |
50 |
// Obtener el vector con la ventanas de muestras
|
51 |
for (int band = 0; band < numberOfBandsToProcess(); band++) { |
52 |
int k = 0; |
53 |
for (int i = -halfSide; i <= halfSide; i++) |
54 |
for (int j = -halfSide; j <= halfSide; j++) { |
55 |
if ((col + i >= 0) && (line + j >= 0) && (col + i < width) && (line + j < height)) { |
56 |
window[k] = raster.getElemInt(line + j, col + i, band) & 0xff;
|
57 |
k++; |
58 |
} |
59 |
} |
60 |
// Ordenar los valores de las ventanas, se supone que usa quickSort.
|
61 |
Arrays.sort(window, 0, k); |
62 |
|
63 |
// Extraer los elementos centrales y asignarselos al pixel (x,y)
|
64 |
rasterResult.setElem(line, col, band, (int) window[k >> 1]); |
65 |
} |
66 |
} |
67 |
|
68 |
public int getInRasterDataType() { |
69 |
return RasterBuffer.TYPE_INT;
|
70 |
} |
71 |
|
72 |
public int getOutRasterDataType() { |
73 |
return RasterBuffer.TYPE_INT;
|
74 |
} |
75 |
} |