svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / EqualizationShortFilter.java @ 24831
History | View | Annotate | Download (2.85 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 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.dataset.IBuffer; |
22 |
/**
|
23 |
* Filtro de ecualizaci?n de histograma para tipo de datos short.
|
24 |
*
|
25 |
* @version 11/05/2007
|
26 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
27 |
*/
|
28 |
public class EqualizationShortFilter extends EqualizationFilter { |
29 |
|
30 |
/*
|
31 |
* (non-Javadoc)
|
32 |
* @see org.gvsig.raster.grid.filter.enhancement.LinearEnhancementFilter#process(int, int)
|
33 |
*/
|
34 |
public void process(int col, int line) { |
35 |
for (int iBand = 0; iBand < raster.getBandCount(); iBand++) { |
36 |
short p = raster.getElemShort(line, col, iBand);
|
37 |
if(!equalizationActive(iBand)) {
|
38 |
rasterResult.setElem(line, col, iBand, p); |
39 |
continue;
|
40 |
} |
41 |
|
42 |
if (p > maxBandValue[renderBands[iBand]])
|
43 |
p = (short) maxBandValue[renderBands[iBand]];
|
44 |
else if (p < minBandValue[renderBands[iBand]]) |
45 |
p = (short) minBandValue[renderBands[iBand]];
|
46 |
|
47 |
int pos = (int)(((p + dto[iBand]) * nClasses) / distance[iBand]); |
48 |
int ecualizationPositive = (int)(lahe[renderBands[iBand]][pos]); |
49 |
int ecualizationNegative = (int)(lahe[renderBands[iBand]][nElements - pos]); |
50 |
double value = ((nElements - ecualizationNegative) + ecualizationPositive) / 2; |
51 |
|
52 |
rasterResult.setElem(line, col, iBand, (short)value);
|
53 |
} |
54 |
} |
55 |
|
56 |
double[] distance = null; |
57 |
double[] dto = null; |
58 |
/*
|
59 |
* (non-Javadoc)
|
60 |
* @see org.gvsig.raster.grid.filter.RasterFilter#pre()
|
61 |
*/
|
62 |
public void pre() { |
63 |
super.pre();
|
64 |
distance = new double[raster.getBandCount()]; |
65 |
dto = new double[raster.getBandCount()]; |
66 |
for (int i = 0; i < raster.getBandCount(); i++) { |
67 |
distance[i] = maxBandValue[renderBands[i]] - minBandValue[renderBands[i]]; |
68 |
dto[i] = -minBandValue[renderBands[i]]; |
69 |
} |
70 |
} |
71 |
|
72 |
/*
|
73 |
* (non-Javadoc)
|
74 |
* @see org.gvsig.raster.grid.filter.enhancement.LinearEnhancementFilter#getInRasterDataType()
|
75 |
*/
|
76 |
public int getInRasterDataType() { |
77 |
return IBuffer.TYPE_SHORT;
|
78 |
} |
79 |
|
80 |
/*
|
81 |
* (non-Javadoc)
|
82 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getOutRasterDataType()
|
83 |
*/
|
84 |
public int getOutRasterDataType() { |
85 |
return IBuffer.TYPE_SHORT;
|
86 |
} |
87 |
} |