Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / convolution / ConvolutionIntegerFilter.java @ 12176

History | View | Annotate | Download (2.21 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
        protected IBuffer                rasterResult = null;
15
        
16
        
17
        public ConvolutionIntegerFilter(){
18
                super();        
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
         * parametro el kernel se pretende aplicar.
23
         * **/
24
        public ConvolutionIntegerFilter(Kernel k){
25
                super();
26
                super.kernel=k;
27
        }
28
        
29
        public void pre(){
30
                super.pre();
31
                rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_INT, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
32
        }
33

    
34
        /** Aplicacion del filtro para el pixel de la posicion line, col */
35
        public void process(int col, int line) {
36
                
37
                int lado= kernel.getLado();
38
                int semiLado = (lado - 1) >> 1;
39
                double ventana[][]= new double[lado][lado];
40
                int 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)){
43
                                for (int j = -semiLado; j <= semiLado; j++)
44
                                        for (int i = -semiLado; i <= semiLado; i++)
45
                                                ventana[i + semiLado][j + semiLado] = raster.getElemInt(line + j, col + i, band)&0xff;;
46
                                Kernel Kventana= new Kernel(ventana);
47
                                resultConvolution=(int)kernel.convolution(Kventana);
48
                                rasterResult.setElem(line, col, band,(int)resultConvolution);        
49
                        }
50
                        else rasterResult.setElem(line, col,band,(int)raster.getElemInt(line,col,band));
51
                }        
52
        }
53
        
54
        /**
55
         * @return  tipo de dato del buffer de entrada
56
         * */                
57
        public int getInRasterDataType() {
58
                return RasterBuffer.TYPE_INT;
59
        }
60

    
61
        /**
62
         * @return  tipo de dato del buffer de salida
63
         * */                
64
        public int getOutRasterDataType() {
65
                return RasterBuffer.TYPE_INT;
66
        }
67
                
68
        
69
        /**
70
         * @return  buffer resultante tras aplicar el filtro
71
         * */
72
        public Object getResult(String name) {
73
                if (name.equals("raster"))
74
                        return (Object) this.rasterResult;
75
                return null;
76
        }
77
        
78
}