Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / ContrastFilter.java @ 18353

History | View | Annotate | Download (4.24 KB)

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