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 / convolution / ConvolutionDoubleFilter.java @ 2438
History | View | Annotate | Download (3.16 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.convolution; |
23 |
|
24 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
25 |
import org.gvsig.fmap.dal.coverage.exception.FilterAddException; |
26 |
import org.gvsig.raster.impl.DefaultRasterManager; |
27 |
import org.gvsig.raster.impl.buffer.RasterBuffer; |
28 |
import org.gvsig.raster.impl.datastruct.Kernel; |
29 |
|
30 |
/**
|
31 |
* Filtro de convolucion para Buffer de tipo Double
|
32 |
* @author Alejandro Mu?oz <alejandro.munoz@uclm.es>
|
33 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
34 |
* */
|
35 |
|
36 |
public class ConvolutionDoubleFilter extends ConvolutionFilter { |
37 |
|
38 |
public ConvolutionDoubleFilter() {
|
39 |
super();
|
40 |
} |
41 |
/**
|
42 |
* @param Kernel a aplicar. En caso de que no se trate de un kernel definido en ConvolutionFilter, se puede pasar como
|
43 |
* parametro el kernel se pretende aplicar.
|
44 |
* **/
|
45 |
public ConvolutionDoubleFilter(Kernel k) { |
46 |
super();
|
47 |
super.kernel = k;
|
48 |
} |
49 |
|
50 |
|
51 |
public void pre() throws FilterAddException { |
52 |
super.pre();
|
53 |
rasterResult = DefaultRasterManager.getInstance().createBuffer(Buffer.TYPE_DOUBLE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true); |
54 |
} |
55 |
|
56 |
|
57 |
/** Aplicacion del filtro para el pixel de la posicion line, col */
|
58 |
public void process(int col, int line) { |
59 |
|
60 |
int lado= kernel.getLado();
|
61 |
int semiLado = (lado - 1) >> 1; |
62 |
double ventana[][] = new double[lado][lado]; |
63 |
double resultConvolution=0; |
64 |
for (int band = 0; band < numberOfBandsToProcess(); band++) { |
65 |
if ((col - semiLado >= 0) && (line - semiLado >= 0) && (col + semiLado < width) && (line + semiLado < height)){ |
66 |
for (int j = -semiLado; j <= semiLado; j++) |
67 |
for (int i = -semiLado; i <= semiLado; i++) |
68 |
ventana[i + semiLado][j + semiLado] = raster.getElemDouble(line + j, col + i, band); |
69 |
Kernel Kventana= new Kernel(ventana); |
70 |
resultConvolution=(double)kernel.convolution(Kventana);
|
71 |
if (resultConvolution<0) |
72 |
resultConvolution = 0;
|
73 |
rasterResult.setElem(line, col, band,resultConvolution); |
74 |
} |
75 |
else rasterResult.setElem(line, col,band,raster.getElemDouble(line,col,band));
|
76 |
} |
77 |
} |
78 |
|
79 |
/**
|
80 |
* @return tipo de dato del buffer de entrada
|
81 |
* */
|
82 |
public int getInRasterDataType() { |
83 |
return RasterBuffer.TYPE_DOUBLE;
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* @return tipo de dato del buffer de salida
|
88 |
* */
|
89 |
public int getOutRasterDataType() { |
90 |
return RasterBuffer.TYPE_DOUBLE;
|
91 |
} |
92 |
|
93 |
} |