svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / segmentation / FirstDerivativeByteFilter.java @ 27361
History | View | Annotate | Download (2.88 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.grid.filter.segmentation; |
20 |
|
21 |
import org.gvsig.raster.buffer.RasterBuffer; |
22 |
/**
|
23 |
* Filtro de primera derivada que se aplica en la imagen. Toma como entrada la imagen y el
|
24 |
* umbral (cero para no umbralizar).
|
25 |
*
|
26 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
27 |
*/
|
28 |
public class FirstDerivativeByteFilter extends FirstDerivativeFilter { |
29 |
/*
|
30 |
* (non-Javadoc)
|
31 |
* @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
|
32 |
*/
|
33 |
public void process(int col, int line) throws InterruptedException { |
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 < raster.getBandCount(); 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[j + semiLado][i + semiLado] = raster.getElemByte(line + j, col + i, band) & 0xff;
|
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.getElemByte(line, col, band));
|
79 |
} |
80 |
} |
81 |
} |
82 |
|
83 |
/*
|
84 |
* (non-Javadoc)
|
85 |
* @see org.gvsig.raster.grid.filter.segmentation.FirstDerivativeFilter#getInRasterDataType()
|
86 |
*/
|
87 |
public int getInRasterDataType() { |
88 |
return RasterBuffer.TYPE_BYTE;
|
89 |
} |
90 |
} |