Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / enhancement / EqualizationShortFilter.java @ 2308

History | View | Annotate | Download (2.55 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.impl.grid.filter.enhancement;
23

    
24
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
25
import org.gvsig.fmap.dal.coverage.exception.FilterAddException;
26
/**
27
 * Filtro de ecualizaci?n de histograma para tipo de datos short.
28
 *
29
 * @author Nacho Brodin (nachobrodin@gmail.com)
30
 */
31
public class EqualizationShortFilter extends EqualizationFilter {
32

    
33
        public void process(int col, int line) {
34
                for (int iBand = 0; iBand < numberOfBandsToProcess(); iBand++) {
35
                        short p = raster.getElemShort(line, col, iBand);
36
                        if(!equalizationActive(iBand)) {
37
                                rasterResult.setElem(line, col, iBand, p);
38
                                continue;
39
                        }
40
                        
41
                        /*if (p > maxBandValue[renderBands[iBand]])
42
                                p = (short) maxBandValue[renderBands[iBand]];
43
                        else if (p < minBandValue[renderBands[iBand]])
44
                                p = (short) minBandValue[renderBands[iBand]];*/
45
                
46
                        int pos = (int)(((p + dto[iBand]) * nClasses) / distance[iBand]);
47
                        int ecualizationPositive = (int)(lahe[iBand][pos]);
48
                        int ecualizationNegative = (int)(lahe[iBand][nElements - pos]);
49
                        double value = ((nElements - ecualizationNegative) + ecualizationPositive) / 2;
50
                        
51
                        rasterResult.setElem(line, col, iBand, (short)value);
52
                }
53
        }
54
        
55
        double[] distance = null;
56
        double[] dto = null;
57

    
58
        public void pre() throws FilterAddException {
59
                super.pre();
60
                distance = new double[raster.getBandCount()];
61
                dto = new double[raster.getBandCount()];
62
                for (int i = 0; i < raster.getBandCount(); i++) {
63
                        distance[i] = maxBandValue[renderBands[i]] - minBandValue[renderBands[i]];
64
                        dto[i] = -minBandValue[renderBands[i]];
65
                }
66
        }
67

    
68
        public int getInRasterDataType() {
69
                return Buffer.TYPE_SHORT;
70
        }
71
        
72
        public int getOutRasterDataType() {
73
                return Buffer.TYPE_SHORT;
74
        }
75
}