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