root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / segmentation / FirstDerivativeShortFilter.java @ 11986
History | View | Annotate | Download (3.47 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 |
import org.gvsig.raster.dataset.IBuffer; |
23 |
/**
|
24 |
* Filtro de Sobel que se aplica en la imagen. Toma como entrada la imagen y el
|
25 |
* umbral (cero para no umbralizar).
|
26 |
*
|
27 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
28 |
*/
|
29 |
public class FirstDerivativeShortFilter extends FirstDerivativeFilter { |
30 |
protected IBuffer rasterResult = null; |
31 |
|
32 |
/**
|
33 |
* Constructor para la asignaci?n del identificador del filtro
|
34 |
* @param fName Cadena que representa el identificador del filtro
|
35 |
*/
|
36 |
public FirstDerivativeShortFilter() {
|
37 |
super();
|
38 |
} |
39 |
|
40 |
/*
|
41 |
* (non-Javadoc)
|
42 |
* @see org.gvsig.raster.grid.filter.segmentation.FirstDerivativeFilter#pre()
|
43 |
*/
|
44 |
public void pre() { |
45 |
super.pre();
|
46 |
rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_SHORT, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
|
47 |
} |
48 |
|
49 |
/*
|
50 |
* (non-Javadoc)
|
51 |
* @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
|
52 |
*/
|
53 |
public void process(int col, int line) { |
54 |
int out;
|
55 |
int convoResult[] = new int[4]; |
56 |
int ladoVentana = 3; |
57 |
int semiLado = (ladoVentana - 1) >> 1; |
58 |
|
59 |
double ventana[][] = new double[ladoVentana][ladoVentana]; |
60 |
|
61 |
Kernel kernel = null; |
62 |
|
63 |
for (int band = 0; band < raster.getBandCount(); band++) { |
64 |
if ((col - semiLado >= 0) && (line - semiLado >= 0) && (col + semiLado < width) && (line + semiLado < height)) { |
65 |
// Obtener el vector con la ventanas de muestras
|
66 |
for (int j = -semiLado; j <= semiLado; j++) |
67 |
for (int i = -semiLado; i <= semiLado; i++) |
68 |
ventana[i + semiLado][j + semiLado] = raster.getElemShort(line + j, col + i, band); |
69 |
|
70 |
kernel = new Kernel(ventana); |
71 |
|
72 |
convoResult[0] = (int) operatorH.convolution(kernel); |
73 |
convoResult[1] = (int) operatorV.convolution(kernel); |
74 |
|
75 |
if (compare) {
|
76 |
if (convoResult[0] > convoResult[1]) |
77 |
out = convoResult[0];
|
78 |
else
|
79 |
out = convoResult[1];
|
80 |
} else {
|
81 |
out = (int) Math.sqrt(Math.pow(convoResult[0], 2) + Math.pow(convoResult[1], 2)); |
82 |
} |
83 |
|
84 |
if (umbral > 0) { |
85 |
if (out >= umbral)
|
86 |
out = 255;
|
87 |
else
|
88 |
out = 0;
|
89 |
} else {
|
90 |
if (out < 0) |
91 |
out = 0;
|
92 |
else if (out > 255) |
93 |
out = 255;
|
94 |
} |
95 |
|
96 |
rasterResult.setElem(line, col, band, (short) out);
|
97 |
} else {
|
98 |
rasterResult.setElem(line, col, band, (short) raster.getElemShort(line, col, band));
|
99 |
} |
100 |
} |
101 |
} |
102 |
|
103 |
public int getInRasterDataType() { |
104 |
return RasterBuffer.TYPE_SHORT;
|
105 |
} |
106 |
|
107 |
public int getOutRasterDataType() { |
108 |
return RasterBuffer.TYPE_SHORT;
|
109 |
} |
110 |
|
111 |
public Object getResult(String name) { |
112 |
if (name.equals("raster")) { |
113 |
return (Object) this.rasterResult; |
114 |
} else {
|
115 |
return null; |
116 |
} |
117 |
} |
118 |
} |