Statistics
| Revision:

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

History | View | Annotate | Download (4.43 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 18388 bsanchez
import org.gvsig.raster.dataset.IBuffer;
23 11652 bsanchez
import org.gvsig.raster.dataset.Params;
24 10740 nacho
import org.gvsig.raster.grid.filter.RasterFilter;
25
/**
26
 * Clase base para todos los filtros de contraste
27 12333 bsanchez
 *
28 12138 bsanchez
 * @version 31/05/2007
29 11574 nacho
 * @author Miguel ?ngel Querol Carratal?  (miguelangel.querol@iver.es)
30 10740 nacho
 */
31 11714 bsanchez
public class ContrastFilter extends RasterFilter {
32 12008 bsanchez
        public static String[]        names = new String[] {"contrast"};
33 11942 bsanchez
34 10740 nacho
        /**
35
         * Variable que contendra el incremento del contraste.
36
         */
37
        int incrContraste = 0;
38 11942 bsanchez
39 10740 nacho
        /**
40 12333 bsanchez
         * Constructor. Llama al constructor de la clase base y asigna el
41 12138 bsanchez
         * nombre del filtro.
42 10740 nacho
         */
43
        public ContrastFilter(){
44 11986 bsanchez
                setName(names[0]);
45 10740 nacho
        }
46 11942 bsanchez
47 11899 bsanchez
        /*
48
         * (non-Javadoc)
49
         * @see org.gvsig.raster.grid.filter.RasterFilter#pre()
50
         */
51 10740 nacho
        public void pre() {
52 12008 bsanchez
                exec = true;
53 17108 nbrodin
                raster = rasterResult;
54 12008 bsanchez
                raster = (RasterBuffer) params.get("raster");
55
                height = raster.getHeight();
56
                width = raster.getWidth();
57
                incrContraste = ((Integer) params.get("incrContraste")).intValue();
58 18388 bsanchez
                rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
59 10740 nacho
        }
60
61 11899 bsanchez
        /*
62
         * (non-Javadoc)
63
         * @see org.gvsig.raster.grid.filter.RasterFilter#post()
64
         */
65 10740 nacho
        public void post() {
66 11899 bsanchez
                // En caso de que nadie apunte a raster, se liberar? su memoria.
67
                raster = null;
68 10740 nacho
        }
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 11942 bsanchez
78 11652 bsanchez
        /*
79
         * (non-Javadoc)
80
         * @see org.gvsig.raster.grid.filter.IRasterFilter#getGroup()
81
         */
82
        public String getGroup() {
83 19859 nbrodin
                return "realces";
84 11652 bsanchez
        }
85 11942 bsanchez
86 11652 bsanchez
        /*
87
         * (non-Javadoc)
88
         * @see org.gvsig.raster.grid.filter.IRasterFilter#getParams()
89
         */
90 12030 bsanchez
        public Params getUIParams(String nameFilter) {
91 11672 bsanchez
                Params params = new Params();
92
                params.setParam("Contrast",
93 14249 nbrodin
                                new Integer(incrContraste),
94 11672 bsanchez
                                Params.SLIDER,
95 11706 bsanchez
                                new String[]{ "-255", "255", "50", "1", "25" }); //min, max, valor defecto, intervalo peque?o, intervalo grande;
96 11672 bsanchez
                return params;
97 11652 bsanchez
        }
98
99
        /*
100
         * (non-Javadoc)
101 11714 bsanchez
         * @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 18388 bsanchez
                return RasterBuffer.TYPE_BYTE;
113 11714 bsanchez
        }
114
115
        /*
116
         * (non-Javadoc)
117 12008 bsanchez
         * @see org.gvsig.raster.grid.filter.enhancement.ContrastFilter#getResult(java.lang.String)
118 11714 bsanchez
         */
119
        public Object getResult(String name) {
120 21803 bsanchez
                if (name.equals("raster")) {
121
                        if (!exec)
122
                                return this.raster;
123
                        return this.rasterResult;
124
                }
125 11714 bsanchez
                return null;
126
        }
127
128
        /*
129
         * (non-Javadoc)
130
         * @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
131
         */
132 27361 nbrodin
        public void process(int x, int y) throws InterruptedException {
133 11714 bsanchez
        }
134 11942 bsanchez
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 11963 bsanchez
162
        /*
163
         * (non-Javadoc)
164
         * @see org.gvsig.raster.grid.filter.RasterFilter#getNames()
165
         */
166
        public String[] getNames() {
167
                return names;
168
        }
169 11652 bsanchez
}