svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / convolution / ConvolutionIntegerFilter.java @ 27361
History | View | Annotate | Download (2.33 KB)
1 |
package org.gvsig.raster.grid.filter.convolution; |
---|---|
2 |
|
3 |
import org.gvsig.raster.buffer.RasterBuffer; |
4 |
import org.gvsig.raster.dataset.IBuffer; |
5 |
|
6 |
/**
|
7 |
* Filtro de convolucion para Buffer de tipo Int
|
8 |
* @author Alejandro Mu?oz <alejandro.munoz@uclm.es>
|
9 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
10 |
* */
|
11 |
|
12 |
public class ConvolutionIntegerFilter extends ConvolutionFilter { |
13 |
|
14 |
public ConvolutionIntegerFilter(){
|
15 |
super();
|
16 |
} |
17 |
/**
|
18 |
* @param Kernel a aplicar. En caso de que no se trate de un kernel definido en ConvolutionFilter, se puede pasar como
|
19 |
* parametro el kernel se pretende aplicar.
|
20 |
* **/
|
21 |
public ConvolutionIntegerFilter(Kernel k){ |
22 |
super();
|
23 |
super.kernel=k;
|
24 |
} |
25 |
|
26 |
public void pre(){ |
27 |
super.pre();
|
28 |
rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_INT, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
|
29 |
} |
30 |
|
31 |
/** Aplicacion del filtro para el pixel de la posicion line, col */
|
32 |
public void process(int col, int line) throws InterruptedException { |
33 |
int lado = kernel.getLado();
|
34 |
int semiLado = (lado - 1) >> 1; |
35 |
double ventana[][] = new double[lado][lado]; |
36 |
double resultConvolution = 0; |
37 |
for (int band = 0; band < raster.getBandCount(); band++) { |
38 |
if ((col - semiLado >= 0) && (line - semiLado >= 0) && (col + semiLado < width) && (line + semiLado < height)) { |
39 |
for (int j = -semiLado; j <= semiLado; j++) |
40 |
for (int i = -semiLado; i <= semiLado; i++) |
41 |
ventana[i + semiLado][j + semiLado] = raster.getElemInt(line + j, col + i, band) & 0xff;
|
42 |
Kernel Kventana = new Kernel(ventana); |
43 |
resultConvolution = kernel.convolution(Kventana); |
44 |
if (resultConvolution > Integer.MAX_VALUE) |
45 |
resultConvolution = Integer.MAX_VALUE;
|
46 |
else
|
47 |
if (resultConvolution < 0) |
48 |
resultConvolution = 0;
|
49 |
rasterResult.setElem(line, col, band, (int) resultConvolution);
|
50 |
} else
|
51 |
rasterResult.setElem(line, col, band, raster.getElemInt(line, col, band)); |
52 |
} |
53 |
} |
54 |
|
55 |
/**
|
56 |
* @return tipo de dato del buffer de entrada
|
57 |
* */
|
58 |
public int getInRasterDataType() { |
59 |
return RasterBuffer.TYPE_INT;
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* @return tipo de dato del buffer de salida
|
64 |
* */
|
65 |
public int getOutRasterDataType() { |
66 |
return RasterBuffer.TYPE_INT;
|
67 |
} |
68 |
|
69 |
|
70 |
/**
|
71 |
* @return buffer resultante tras aplicar el filtro
|
72 |
* */
|
73 |
public Object getResult(String name) { |
74 |
if (name.equals("raster")) |
75 |
return this.rasterResult; |
76 |
return null; |
77 |
} |
78 |
|
79 |
} |