Revision 15961 trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/convolution/ConvolutionShortFilter.java
ConvolutionShortFilter.java | ||
---|---|---|
5 | 5 |
|
6 | 6 |
/** |
7 | 7 |
* Filtro de convolucion para Buffer de tipo Short |
8 |
* @author Alejandro Mu?oz <alejandro.munoz@uclm.es>
|
|
9 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
|
8 |
* @author Alejandro Mu?oz <alejandro.munoz@uclm.es> |
|
9 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es> |
|
10 | 10 |
* */ |
11 | 11 |
public class ConvolutionShortFilter extends ConvolutionFilter { |
12 | 12 |
|
13 | 13 |
protected IBuffer rasterResult = null; |
14 |
|
|
15 |
|
|
14 |
|
|
15 |
|
|
16 | 16 |
public ConvolutionShortFilter(){ |
17 | 17 |
super(); |
18 | 18 |
} |
19 |
|
|
20 |
/**
|
|
21 |
* @param Kernel a aplicar. En caso de que no se trate de un kernel definido en ConvolutionFilter, se puede pasar como
|
|
19 |
|
|
20 |
/** |
|
21 |
* @param Kernel a aplicar. En caso de que no se trate de un kernel definido en ConvolutionFilter, se puede pasar como |
|
22 | 22 |
* parametro el kernel se pretende aplicar. |
23 | 23 |
* **/ |
24 | 24 |
public ConvolutionShortFilter(Kernel k){ |
25 | 25 |
super(); |
26 | 26 |
super.kernel=k; |
27 | 27 |
} |
28 |
|
|
28 |
|
|
29 | 29 |
public void pre(){ |
30 | 30 |
super.pre(); |
31 | 31 |
rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_SHORT, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true); |
... | ... | |
33 | 33 |
|
34 | 34 |
/** Aplicacion del filtro para el pixel de la posicion line, col */ |
35 | 35 |
public void process(int col, int line) { |
36 |
|
|
37 |
int lado= kernel.getLado(); |
|
36 |
int lado = kernel.getLado(); |
|
38 | 37 |
int semiLado = (lado - 1) >> 1; |
39 |
double ventana[][]= new double[lado][lado]; |
|
40 |
double resultConvolution=0;
|
|
41 |
for (int band = 0; band < raster.getBandCount(); band++) {
|
|
42 |
if ((col - semiLado >= 0) && (line - semiLado >= 0) && (col + semiLado < width) && (line + semiLado < height)){ |
|
38 |
double ventana[][] = new double[lado][lado];
|
|
39 |
double resultConvolution = 0;
|
|
40 |
for (int band = 0; band < raster.getBandCount(); band++) { |
|
41 |
if ((col - semiLado >= 0) && (line - semiLado >= 0) && (col + semiLado < width) && (line + semiLado < height)) {
|
|
43 | 42 |
for (int j = -semiLado; j <= semiLado; j++) |
44 | 43 |
for (int i = -semiLado; i <= semiLado; i++) |
45 |
ventana[i + semiLado][j + semiLado] = raster.getElemShort(line + j, col + i, band)&0xff;; |
|
46 |
Kernel Kventana= new Kernel(ventana); |
|
47 |
resultConvolution=kernel.convolution(Kventana); |
|
48 |
if(resultConvolution>Short.MAX_VALUE) |
|
49 |
resultConvolution=Short.MAX_VALUE; |
|
50 |
else if (resultConvolution<0) |
|
51 |
resultConvolution = 0; |
|
52 |
rasterResult.setElem(line, col, band,(short)resultConvolution); |
|
53 |
} |
|
54 |
else rasterResult.setElem(line, col,band,(short)raster.getElemShort(line,col,band)); |
|
55 |
} |
|
44 |
ventana[i + semiLado][j + semiLado] = raster.getElemShort(line + j, col + i, band) & 0xff; |
|
45 |
Kernel Kventana = new Kernel(ventana); |
|
46 |
resultConvolution = kernel.convolution(Kventana); |
|
47 |
if (resultConvolution > Short.MAX_VALUE) |
|
48 |
resultConvolution = Short.MAX_VALUE; |
|
49 |
else |
|
50 |
if (resultConvolution < 0) |
|
51 |
resultConvolution = 0; |
|
52 |
rasterResult.setElem(line, col, band, (short) resultConvolution); |
|
53 |
} else |
|
54 |
rasterResult.setElem(line, col, band, (short) raster.getElemShort(line, col, band)); |
|
55 |
} |
|
56 | 56 |
} |
57 |
|
|
57 |
|
|
58 | 58 |
/** |
59 | 59 |
* @return tipo de dato del buffer de entrada |
60 |
* */
|
|
60 |
* */ |
|
61 | 61 |
public int getInRasterDataType() { |
62 | 62 |
return RasterBuffer.TYPE_SHORT; |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
/** |
66 | 66 |
* @return tipo de dato del buffer de salida |
67 |
* */
|
|
67 |
* */ |
|
68 | 68 |
public int getOutRasterDataType() { |
69 | 69 |
return RasterBuffer.TYPE_SHORT; |
70 | 70 |
} |
... | ... | |
77 | 77 |
return (Object) this.rasterResult; |
78 | 78 |
return null; |
79 | 79 |
} |
80 |
|
|
80 |
|
|
81 | 81 |
} |
Also available in: Unified diff