root / trunk / libraries / libCq_CMS_praster / src / org / cresques / filter / segmentation / FirstDerivativeFilter.java @ 8026
History | View | Annotate | Download (3.71 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
|
20 |
package org.cresques.filter.segmentation; |
21 |
|
22 |
import java.awt.Image; |
23 |
|
24 |
import org.cresques.filter.RasterFilter; |
25 |
import org.cresques.io.data.RasterBuf; |
26 |
import org.gvsig.i18n.Messages; |
27 |
|
28 |
/**
|
29 |
* Clase base para los filtros Sobel.
|
30 |
*
|
31 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
32 |
*
|
33 |
*/
|
34 |
|
35 |
public abstract class FirstDerivativeFilter extends RasterFilter { |
36 |
public static final int TYPE_SOBEL = 0; |
37 |
public static final int TYPE_ROBERTS = 1; |
38 |
public static final int TYPE_PREWITT = 2; |
39 |
public static final int TYPE_FREICHEN = 3; |
40 |
|
41 |
protected int umbral = 0; |
42 |
protected boolean compare = false; |
43 |
protected Image imageResult = null; |
44 |
protected RasterBuf rasterResult = null; |
45 |
protected Kernel operatorH; |
46 |
protected Kernel operatorV; |
47 |
protected int operator; |
48 |
|
49 |
// Kernels:------------------------------------------
|
50 |
double sobelH[][]= {{-1,0,1},{-2,0,2},{-1,0,1}}; |
51 |
double sobelV[][]= {{-1,-2,-1},{0,0,0},{1,2,1}}; |
52 |
Kernel sobelHKernel = new Kernel(sobelH); |
53 |
Kernel sobelVKernel = new Kernel(sobelV); |
54 |
|
55 |
double robertsH[][]= {{0,0,-1},{0,1,0},{0,0,0}}; |
56 |
double robertsV[][]= {{-1,0,0},{0,1,0},{0,0,0}}; |
57 |
Kernel robertsHKernel = new Kernel(robertsH); |
58 |
Kernel robertsVKernel = new Kernel(robertsV); |
59 |
|
60 |
double prewittH[][]= {{1,0,-1},{1,0,-1},{1,0,-1}}; |
61 |
double prewittV[][]= {{-1,-1,-1},{0,0,0},{1,1,1}}; |
62 |
Kernel prewittHKernel = new Kernel(prewittH); |
63 |
Kernel prewittVKernel = new Kernel(prewittV); |
64 |
|
65 |
double freiChenH[][]= {{1,0,-1},{1.4142D,0,-1.4142D},{1,0,-1}}; |
66 |
double freiChenV[][]= {{-1,-1.4142D,-1},{0,0,0},{1,1.4142D,1}}; |
67 |
Kernel freiChenHKernel = new Kernel(freiChenH); |
68 |
Kernel freiChenVKernel = new Kernel(freiChenV); |
69 |
// --------------------------------------------------
|
70 |
|
71 |
|
72 |
public FirstDerivativeFilter() {
|
73 |
super();
|
74 |
} |
75 |
|
76 |
/**
|
77 |
* Constructor para la asignaci?n del identificador del filtro
|
78 |
* @param fName Cadena que representa el identificador del filtro
|
79 |
*/
|
80 |
public FirstDerivativeFilter(String fName) { |
81 |
super();
|
82 |
super.filterName = fName;
|
83 |
} |
84 |
|
85 |
public void pre() { |
86 |
if (params.get("umbral")!=null) |
87 |
umbral = ((Integer)params.get("umbral")).intValue(); |
88 |
else this.umbral = 0; |
89 |
|
90 |
if (params.get("compare")!=null) |
91 |
compare = ((Boolean)params.get("compare")).booleanValue(); |
92 |
else this.compare = false; |
93 |
|
94 |
if (params.get("operator")!=null) |
95 |
operator = ((Integer)params.get("operator")).intValue(); |
96 |
else this.operator = 0; |
97 |
|
98 |
switch (operator){
|
99 |
case TYPE_SOBEL:
|
100 |
operatorH=sobelHKernel; |
101 |
operatorV=sobelVKernel; |
102 |
break;
|
103 |
case TYPE_ROBERTS:
|
104 |
operatorH=robertsHKernel; |
105 |
operatorV=robertsVKernel; |
106 |
break;
|
107 |
case TYPE_PREWITT:
|
108 |
operatorH=prewittHKernel; |
109 |
operatorV=prewittVKernel; |
110 |
break;
|
111 |
case TYPE_FREICHEN:
|
112 |
operatorH=freiChenHKernel; |
113 |
operatorV=freiChenVKernel; |
114 |
break;
|
115 |
} |
116 |
} |
117 |
|
118 |
public void post() { |
119 |
// TODO Auto-generated method stub
|
120 |
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Obtiene el umbral
|
125 |
* @return entero que representa el umbral
|
126 |
*/
|
127 |
public int getUmbral() { |
128 |
return umbral;
|
129 |
} |
130 |
|
131 |
} |