Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / segmentation / FirstDerivativeFloatFilter.java @ 2308

History | View | Annotate | Download (2.89 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.segmentation;
23

    
24
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
25
import org.gvsig.raster.impl.datastruct.Kernel;
26
/**
27
 * Filtro de primera derivada que se aplica en la imagen. Toma como entrada la imagen y el
28
 * umbral (cero para no umbralizar).
29
 * 
30
 * @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
31
 */
32
public class FirstDerivativeFloatFilter extends FirstDerivativeFilter {
33
        public void process(int col, int line) {
34
                int out;
35
                int convoResult[] = new int[4];
36
                int ladoVentana = 3;
37
                int semiLado = (ladoVentana - 1) >> 1;
38

    
39
                double ventana[][] = new double[ladoVentana][ladoVentana];
40

    
41
                Kernel kernel = null;
42

    
43
                for (int band = 0; band < nBandsToProcess; band++) {
44
                        if ((col - semiLado >= 0) && (line - semiLado >= 0) && (col + semiLado < width) && (line + semiLado < height)) {
45
                                // Obtener el vector con la ventanas de muestras
46
                                for (int j = -semiLado; j <= semiLado; j++)
47
                                        for (int i = -semiLado; i <= semiLado; i++)
48
                                                ventana[i + semiLado][j + semiLado] = raster.getElemFloat(line + j, col + i, band);
49

    
50
                                kernel = new Kernel(ventana);
51

    
52
                                convoResult[0] = (int) operatorH.convolution(kernel);
53
                                convoResult[1] = (int) operatorV.convolution(kernel);
54

    
55
                                if (compare) {
56
                                        if (convoResult[0] > convoResult[1])
57
                                                out = convoResult[0];
58
                                        else
59
                                                out = convoResult[1];
60
                                } else {
61
                                        out = (int) Math.sqrt(Math.pow(convoResult[0], 2) + Math.pow(convoResult[1], 2));
62
                                }
63

    
64
                                if (umbral > 0) {
65
                                        if (out >= (255 - umbral))
66
                                                out = 255;
67
                                        else
68
                                                out = 0;
69
                                } else {
70
                                        if (out < 0)
71
                                                out = 0;
72
                                        else if (out > 255)
73
                                                out = 255;
74
                                }
75

    
76
                                rasterResult.setElem(line, col, band, (byte) out);
77
                        } else {
78
                                rasterResult.setElem(line, col, band, (byte) raster.getElemFloat(line, col, band));
79
                        }
80
                }
81
                
82
                if(hasTransparency)  
83
                        rasterResult.setElem(line, col, rasterResult.getBandCount() - 1, 
84
                                        raster.getElemFloat(line, col, raster.getBandCount() - 1));
85
        }
86

    
87
        public int getInRasterDataType() {
88
                return Buffer.TYPE_FLOAT;
89
        }
90
}