root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / ContrastFilter.java @ 21803
History | View | Annotate | Download (4.4 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 |
package org.gvsig.raster.grid.filter.enhancement; |
20 |
|
21 |
import org.gvsig.raster.buffer.RasterBuffer; |
22 |
import org.gvsig.raster.dataset.IBuffer; |
23 |
import org.gvsig.raster.dataset.Params; |
24 |
import org.gvsig.raster.grid.filter.RasterFilter; |
25 |
/**
|
26 |
* Clase base para todos los filtros de contraste
|
27 |
*
|
28 |
* @version 31/05/2007
|
29 |
* @author Miguel ?ngel Querol Carratal? (miguelangel.querol@iver.es)
|
30 |
*/
|
31 |
public class ContrastFilter extends RasterFilter { |
32 |
public static String[] names = new String[] {"contrast"}; |
33 |
|
34 |
/**
|
35 |
* Variable que contendra el incremento del contraste.
|
36 |
*/
|
37 |
int incrContraste = 0; |
38 |
|
39 |
/**
|
40 |
* Constructor. Llama al constructor de la clase base y asigna el
|
41 |
* nombre del filtro.
|
42 |
*/
|
43 |
public ContrastFilter(){
|
44 |
setName(names[0]);
|
45 |
} |
46 |
|
47 |
/*
|
48 |
* (non-Javadoc)
|
49 |
* @see org.gvsig.raster.grid.filter.RasterFilter#pre()
|
50 |
*/
|
51 |
public void pre() { |
52 |
exec = true;
|
53 |
raster = rasterResult; |
54 |
raster = (RasterBuffer) params.get("raster");
|
55 |
height = raster.getHeight(); |
56 |
width = raster.getWidth(); |
57 |
incrContraste = ((Integer) params.get("incrContraste")).intValue(); |
58 |
rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
|
59 |
} |
60 |
|
61 |
/*
|
62 |
* (non-Javadoc)
|
63 |
* @see org.gvsig.raster.grid.filter.RasterFilter#post()
|
64 |
*/
|
65 |
public void post() { |
66 |
// En caso de que nadie apunte a raster, se liberar? su memoria.
|
67 |
raster = null;
|
68 |
} |
69 |
|
70 |
/**
|
71 |
* Obtiene el incremento de contraster que se est? aplicando
|
72 |
* @return entero que representa el incremento de contraste aplicado.
|
73 |
*/
|
74 |
public int getContrastIncrease(){ |
75 |
return this.incrContraste; |
76 |
} |
77 |
|
78 |
/*
|
79 |
* (non-Javadoc)
|
80 |
* @see org.gvsig.raster.grid.filter.IRasterFilter#getGroup()
|
81 |
*/
|
82 |
public String getGroup() { |
83 |
return "realces"; |
84 |
} |
85 |
|
86 |
/*
|
87 |
* (non-Javadoc)
|
88 |
* @see org.gvsig.raster.grid.filter.IRasterFilter#getParams()
|
89 |
*/
|
90 |
public Params getUIParams(String nameFilter) { |
91 |
Params params = new Params();
|
92 |
params.setParam("Contrast",
|
93 |
new Integer(incrContraste), |
94 |
Params.SLIDER, |
95 |
new String[]{ "-255", "255", "50", "1", "25" }); //min, max, valor defecto, intervalo peque?o, intervalo grande; |
96 |
return params;
|
97 |
} |
98 |
|
99 |
/*
|
100 |
* (non-Javadoc)
|
101 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getInRasterDataType()
|
102 |
*/
|
103 |
public int getInRasterDataType() { |
104 |
return 0; |
105 |
} |
106 |
|
107 |
/*
|
108 |
* (non-Javadoc)
|
109 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getOutRasterDataType()
|
110 |
*/
|
111 |
public int getOutRasterDataType() { |
112 |
return RasterBuffer.TYPE_BYTE;
|
113 |
} |
114 |
|
115 |
/*
|
116 |
* (non-Javadoc)
|
117 |
* @see org.gvsig.raster.grid.filter.enhancement.ContrastFilter#getResult(java.lang.String)
|
118 |
*/
|
119 |
public Object getResult(String name) { |
120 |
if (name.equals("raster")) { |
121 |
if (!exec)
|
122 |
return this.raster; |
123 |
return this.rasterResult; |
124 |
} |
125 |
return null; |
126 |
} |
127 |
|
128 |
/*
|
129 |
* (non-Javadoc)
|
130 |
* @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
|
131 |
*/
|
132 |
public void process(int x, int y) { |
133 |
} |
134 |
|
135 |
/**
|
136 |
* Algoritmo de contraste
|
137 |
* @param px valor de la banda
|
138 |
* @return valor de la banda con el algoritmo aplicado
|
139 |
*/
|
140 |
protected int calcContrast(int px) { |
141 |
int result;
|
142 |
int diferencia = 127 - px; |
143 |
if (incrContraste >= 0) { |
144 |
result = (int) (px - (0.02 * diferencia * incrContraste)); // ((5.0 * 0.1) / 25) = 0.02 |
145 |
} else {
|
146 |
result = (int) (px - (0.004 * diferencia * incrContraste)); // (0.1 / 25) = 0.004; |
147 |
if (px < 127) { |
148 |
if (result > 127) result = 127; |
149 |
} else {
|
150 |
if (result < 127) result = 127; |
151 |
} |
152 |
} |
153 |
if (result < 0) |
154 |
result = 0;
|
155 |
else {
|
156 |
if (result > 255) |
157 |
result = 255;
|
158 |
} |
159 |
return result;
|
160 |
} |
161 |
|
162 |
/*
|
163 |
* (non-Javadoc)
|
164 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getNames()
|
165 |
*/
|
166 |
public String[] getNames() { |
167 |
return names;
|
168 |
} |
169 |
} |