root / trunk / libraries / libCq_CMS_praster / src / org / cresques / filter / enhancement / LinearEnhancementShortFilter.java @ 8026
History | View | Annotate | Download (4.05 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.filter.enhancement; |
25 |
|
26 |
import java.awt.image.BufferedImage; |
27 |
|
28 |
import org.cresques.io.data.RasterBuf; |
29 |
import org.cresques.io.datastruct.Statistic; |
30 |
|
31 |
|
32 |
/**
|
33 |
* Realzado Lineal (Amplitude Rescaling) para imagenes de 16 bits.
|
34 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
35 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
36 |
*/
|
37 |
public class LinearEnhancementShortFilter extends LinearEnhancementFilter { |
38 |
private short[] px = new short[4]; |
39 |
private int bandsCnt = 3; |
40 |
|
41 |
/**
|
42 |
* Constructor
|
43 |
*/
|
44 |
public LinearEnhancementShortFilter() {
|
45 |
super();
|
46 |
} |
47 |
|
48 |
/* (non-Javadoc)
|
49 |
* @see org.cresques.io.raster.IRasterFilter#pre()
|
50 |
*/
|
51 |
public void pre() { |
52 |
//Obtenci?n de par?metros
|
53 |
this.raster = (RasterBuf) params.get("raster"); |
54 |
this.stats = (Statistic) params.get("stats"); |
55 |
this.removeExtrema = ((Boolean) params.get("remove")).booleanValue(); |
56 |
this.filename = (String) params.get("filename"); |
57 |
height = raster.getHeight(); |
58 |
width = raster.getWidth(); |
59 |
super.pre();
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* Calculo del realce
|
64 |
* @param pt pixel
|
65 |
* @return pixel con el calculo de realce aplicado
|
66 |
*/
|
67 |
private short[] calcLinearEnhancement(short[] px){ |
68 |
for (int i = 0; i < bandsCnt; i++) { |
69 |
if (px[i] > maxBandValue[i]) {
|
70 |
px[i] = (short)maxBandValue[i];
|
71 |
} else if (px[i] < minBandValue[i]) { |
72 |
px[i] = (short)minBandValue[i];
|
73 |
} |
74 |
|
75 |
px[i] = (short)(((short) ((((double) px[i]) * scale[i]) + offset[i])) & 0xff); |
76 |
} |
77 |
return px;
|
78 |
} |
79 |
|
80 |
/* (non-Javadoc)
|
81 |
* @see org.cresques.io.raster.IRasterFilter#process(int, int)
|
82 |
*/
|
83 |
public void process(int col, int line) { |
84 |
raster.getElemShort(line, col, px); |
85 |
px = calcLinearEnhancement(px); |
86 |
raster.setElemShort(line, col, px); |
87 |
} |
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see org.cresques.io.raster.IRasterFilter#processSuperSampling(int, int)
|
91 |
*/
|
92 |
public void processSuperSampling(int col, int line) { |
93 |
raster.getElemShort(line, col, px); |
94 |
px = calcLinearEnhancement(px); |
95 |
for(int j = col; j < raster.getWidth() && j < (col + stepX[contX + 1]); j++) |
96 |
for(int i = line; i < raster.getHeight() && i < (line + stepY[contY + 1]); i++) |
97 |
raster.setElemShort(i, j, px); |
98 |
} |
99 |
|
100 |
/* (non-Javadoc)
|
101 |
* @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String)
|
102 |
*/
|
103 |
public Object getResult(String name) { |
104 |
if (name.equals("raster")) { |
105 |
return (Object) this.raster; |
106 |
} else {
|
107 |
return null; |
108 |
} |
109 |
} |
110 |
|
111 |
/* (non-Javadoc)
|
112 |
* @see org.cresques.io.raster.IRasterFilter#getInRasterDataType()
|
113 |
*/
|
114 |
public int getInRasterDataType() { |
115 |
return RasterBuf.TYPE_SHORT;
|
116 |
} |
117 |
|
118 |
/* (non-Javadoc)
|
119 |
* @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType()
|
120 |
*/
|
121 |
public int getOutRasterDataType() { |
122 |
return RasterBuf.TYPE_SHORT;
|
123 |
} |
124 |
|
125 |
/* (non-Javadoc)
|
126 |
* @see org.cresques.io.raster.IRasterFilter#post()
|
127 |
*/
|
128 |
public void post() { |
129 |
} |
130 |
|
131 |
/* (non-Javadoc)
|
132 |
* @see org.cresques.io.raster.RasterFilter#processLine(int)
|
133 |
*/
|
134 |
public void processLine(int y) { |
135 |
} |
136 |
} |