Revision 19395
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/LinearStretchEnhancementFloatFilter.java | ||
---|---|---|
41 | 41 |
rasterResult.setElem(line, col, iBand, (byte) p); |
42 | 42 |
continue; |
43 | 43 |
} |
44 |
|
|
44 |
|
|
45 | 45 |
processValue(p, stretchs.gray, col, line, iBand); |
46 | 46 |
switch (iBand) { |
47 |
case 0: processValue(p, stretchs.red, col, line, iBand);
|
|
47 |
case 0: processValue(p, scaleOffsetList[0], col, line, iBand);
|
|
48 | 48 |
break; |
49 |
case 1: processValue(p, stretchs.green, col, line, iBand);
|
|
49 |
case 1: processValue(p, scaleOffsetList[1], col, line, iBand);
|
|
50 | 50 |
break; |
51 |
case 2: processValue(p, stretchs.blue, col, line, iBand);
|
|
51 |
case 2: processValue(p, scaleOffsetList[2], col, line, iBand);
|
|
52 | 52 |
break; |
53 | 53 |
} |
54 | 54 |
} |
... | ... | |
66 | 66 |
*/ |
67 | 67 |
private void processValue(float p, Stretch data, int col, int line, int iBand) { |
68 | 68 |
if(data.scale != null) { |
69 |
if (p > data.maxValue) |
|
70 |
p = (float) data.maxValue; |
|
71 |
else if (p < data.minValue) |
|
72 |
p = (float) data.minValue; |
|
73 |
|
|
69 | 74 |
for (int i = 0; i < data.scale.length; i++) { |
70 | 75 |
if(p >= data.stretchIn[i] && p <= data.stretchIn[i + 1]) |
71 | 76 |
p = (float)(((double)p) * data.scale[i] + data.offset[i]); |
72 | 77 |
} |
73 |
rasterResult.setElem(line, col, iBand, (byte) p); |
|
78 |
rasterResult.setElem(line, col, iBand,(byte)(((byte) p) & 0xff) ); |
|
79 |
|
|
74 | 80 |
} |
75 | 81 |
} |
76 | 82 |
|
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/EnhancementStretchListManager.java | ||
---|---|---|
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
/** |
56 |
* Obtiene un objeto LinearStretchParams para una aplicaci?n de realce lineal estandar, es decir, el rango |
|
57 |
* de datos de salida es 0-255 y con solo un tramo para los datos. |
|
58 |
* @param nBands N?mero de bandas |
|
59 |
* @param tailTrim Recorte de colas |
|
60 |
* @param stats Estad?sticas |
|
61 |
* @return LinearStretchParams |
|
62 |
* @throws FileNotOpenException |
|
63 |
* @throws RasterDriverException |
|
64 |
*/ |
|
65 |
public static LinearStretchParams getStandardParam(int nBands, double tailTrim, IStatistics stats) throws FileNotOpenException, RasterDriverException { |
|
66 |
LinearStretchParams leParams = new LinearStretchParams(); |
|
67 |
try { |
|
68 |
stats.calcFullStatistics(); |
|
69 |
} catch (InterruptedException e) { |
|
70 |
return null; |
|
71 |
} |
|
72 |
if(nBands == 1) { |
|
73 |
leParams.gray.stretchIn = new double[]{stats.getMin()[0], stats.getMax()[0]}; |
|
74 |
leParams.gray.stretchOut = new int[]{0, 255}; |
|
75 |
leParams.gray.tailTrimMin = tailTrim; |
|
76 |
leParams.gray.tailTrimMax = tailTrim; |
|
77 |
} |
|
78 |
if(nBands >= 2) { |
|
79 |
leParams.red.stretchIn = new double[]{stats.getMin()[0], stats.getMax()[0]}; |
|
80 |
leParams.red.stretchOut = new int[]{0, 255}; |
|
81 |
leParams.red.tailTrimMin = tailTrim; |
|
82 |
leParams.red.tailTrimMax = tailTrim; |
|
83 |
|
|
84 |
leParams.green.stretchIn = new double[]{stats.getMin()[1], stats.getMax()[1]}; |
|
85 |
leParams.green.stretchOut = new int[]{0, 255}; |
|
86 |
leParams.green.tailTrimMin = tailTrim; |
|
87 |
leParams.green.tailTrimMax = tailTrim; |
|
88 |
} |
|
89 |
if(nBands >= 3) { |
|
90 |
leParams.blue.stretchIn = new double[]{stats.getMin()[2], stats.getMax()[2]}; |
|
91 |
leParams.blue.stretchOut = new int[]{0, 255}; |
|
92 |
leParams.blue.tailTrimMin = tailTrim; |
|
93 |
leParams.blue.tailTrimMax = tailTrim; |
|
94 |
} |
|
95 |
return leParams; |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 | 56 |
* Asigna el objeto con las estadisticas. |
100 | 57 |
* @param stats |
101 | 58 |
*/ |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/LinearStretchParams.java | ||
---|---|---|
67 | 67 |
* Cada elemento del array es un tramo. |
68 | 68 |
*/ |
69 | 69 |
public double[] offset = null; |
70 |
/** |
|
71 |
* Valores m?ximos y m?nimos |
|
72 |
*/ |
|
73 |
public double maxValue = 0; |
|
74 |
public double minValue = 0; |
|
70 | 75 |
|
71 | 76 |
/** |
72 | 77 |
* Aplica el recorte de colas sobre los extremos de los m?ximos y m?nimos de entrada. |
... | ... | |
75 | 80 |
*/ |
76 | 81 |
public void applyTrimToStretchs() { |
77 | 82 |
if(stretchIn != null && stretchIn.length >= 2) { |
78 |
stretchIn[0] = tailTrimValueMin; |
|
79 |
stretchIn[stretchIn.length - 1] = tailTrimValueMax; |
|
83 |
minValue = stretchIn[0] = tailTrimValueMin;
|
|
84 |
maxValue = stretchIn[stretchIn.length - 1] = tailTrimValueMax;
|
|
80 | 85 |
} |
81 | 86 |
} |
82 | 87 |
|
... | ... | |
85 | 90 |
*/ |
86 | 91 |
public void applyRemoveEndsToStretchs(double secondMin, double secondMax) { |
87 | 92 |
if(stretchIn != null && stretchIn.length >= 2) { |
88 |
stretchIn[0] = secondMin; |
|
89 |
stretchIn[stretchIn.length - 1] = secondMax; |
|
93 |
minValue = stretchIn[0] = secondMin;
|
|
94 |
maxValue = stretchIn[stretchIn.length - 1] = secondMax;
|
|
90 | 95 |
} |
91 | 96 |
} |
92 | 97 |
|
... | ... | |
120 | 125 |
public Stretch green = new Stretch(); |
121 | 126 |
public Stretch blue = new Stretch(); |
122 | 127 |
public Stretch gray = new Stretch(); |
123 |
|
|
128 |
|
|
124 | 129 |
/** |
125 |
* Valores de escala a calcular por el filtro lineal por tramos. |
|
126 |
* Cada elemento del array es un tramo. |
|
127 |
*/ |
|
128 |
/*private double[] scaleRed = null; |
|
129 |
private double[] scaleGreen = null; |
|
130 |
private double[] scaleBlue = null; |
|
131 |
private double[] scaleGray = null;*/ |
|
132 |
|
|
133 |
/** |
|
134 |
* Valores de desplazamiento a calcular por el filtro lineal por tramos. |
|
135 |
* Cada elemento del array es un tramo. |
|
136 |
*/ |
|
137 |
/*private double[] offsetRed = null; |
|
138 |
private double[] offsetGreen = null; |
|
139 |
private double[] offsetBlue = null; |
|
140 |
private double[] offsetGray = null;*/ |
|
141 |
|
|
142 |
/** |
|
143 | 130 |
* Consulta si tiene alg?n valor el recorte de colas |
144 | 131 |
* @return true si tiene valor el recorte de colas y false si no lo tiene |
145 | 132 |
*/ |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/LinearStretchEnhancementDoubleFilter.java | ||
---|---|---|
44 | 44 |
|
45 | 45 |
processValue(p, stretchs.gray, col, line, iBand); |
46 | 46 |
switch (iBand) { |
47 |
case 0: processValue(p, stretchs.red, col, line, iBand);
|
|
47 |
case 0: processValue(p, scaleOffsetList[0], col, line, iBand);
|
|
48 | 48 |
break; |
49 |
case 1: processValue(p, stretchs.green, col, line, iBand);
|
|
49 |
case 1: processValue(p, scaleOffsetList[1], col, line, iBand);
|
|
50 | 50 |
break; |
51 |
case 2: processValue(p, stretchs.blue, col, line, iBand);
|
|
51 |
case 2: processValue(p, scaleOffsetList[2], col, line, iBand);
|
|
52 | 52 |
break; |
53 | 53 |
} |
54 | 54 |
} |
... | ... | |
66 | 66 |
*/ |
67 | 67 |
private void processValue(double p, Stretch data, int col, int line, int iBand) { |
68 | 68 |
if(data.scale != null) { |
69 |
if (p > data.maxValue) |
|
70 |
p = (double) data.maxValue; |
|
71 |
else if (p < data.minValue) |
|
72 |
p = (double) data.minValue; |
|
73 |
|
|
69 | 74 |
for (int i = 0; i < data.scale.length; i++) { |
70 | 75 |
if(p >= data.stretchIn[i] && p <= data.stretchIn[i + 1]) |
71 | 76 |
p = (double)(((double)p) * data.scale[i] + data.offset[i]); |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/LinearStretchEnhancementFilter.java | ||
---|---|---|
25 | 25 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
26 | 26 |
import org.gvsig.raster.dataset.properties.DatasetListStatistics; |
27 | 27 |
import org.gvsig.raster.grid.filter.RasterFilter; |
28 |
import org.gvsig.raster.grid.filter.enhancement.LinearStretchParams.Stretch; |
|
28 | 29 |
/** |
29 | 30 |
* Clase base para los filtros de realzado lineal. Lee el m?nimo y m?xmo de la |
30 | 31 |
* clase Statistic que ser?n calculados por PercentTailTrimFilter o |
... | ... | |
38 | 39 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
39 | 40 |
*/ |
40 | 41 |
public class LinearStretchEnhancementFilter extends RasterFilter { |
41 |
protected double[][] scale = null; |
|
42 |
protected double[][] offset = null; |
|
43 |
protected DatasetListStatistics stats = null; |
|
44 |
protected double[] minBandValue = null; |
|
45 |
protected double[] maxBandValue = null; |
|
46 |
protected int nbands = 3; |
|
47 |
protected int[] renderBands = null; |
|
48 |
public static String[] names = new String[] {"enhanced_stretch"}; |
|
49 |
private boolean removeEnds = false; |
|
42 |
protected double[][] scale = null;
|
|
43 |
protected double[][] offset = null;
|
|
44 |
protected DatasetListStatistics stats = null;
|
|
45 |
protected double[] minBandValue = null;
|
|
46 |
protected double[] maxBandValue = null;
|
|
47 |
protected int nbands = 3;
|
|
48 |
protected int[] renderBands = null;
|
|
49 |
public static String[] names = new String[] {"enhanced_stretch"};
|
|
50 |
private boolean removeEnds = false;
|
|
50 | 51 |
|
51 |
protected LinearStretchParams stretchs = null; |
|
52 |
protected LinearStretchParams stretchs = null; |
|
53 |
protected Stretch[] scaleOffsetList = null; |
|
52 | 54 |
|
53 | 55 |
/** |
54 | 56 |
* Construye un LinearEnhancementFilter |
... | ... | |
103 | 105 |
|
104 | 106 |
stretchs.calcLinearScaleAndOffset(); |
105 | 107 |
|
108 |
loadStretchList(); |
|
109 |
|
|
106 | 110 |
nbands = stats.getBandCount(); |
107 | 111 |
rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true); |
108 | 112 |
} |
113 |
|
|
114 |
/** |
|
115 |
* La lista de escalas y desplazamientos es un array de 3 elementos en el que |
|
116 |
* cada posici?n es un objeto Stretch con la escala y desplazamiento de la |
|
117 |
* banda que se dibuja en esa posici?n. El objetivo es aplicar a cada banda |
|
118 |
* el m?ximo y m?nimo que le corresponde. Por ejemplo, cuando tenemos una imagen de |
|
119 |
* 3 bandas de tipo short y queremos visualizar en RGB solo la primera banda entonces |
|
120 |
* escaleOffsetList tendr? stretchs.red en las 3 posiciones. |
|
121 |
*/ |
|
122 |
private void loadStretchList() { |
|
123 |
scaleOffsetList = new Stretch[3]; |
|
124 |
switch (renderBands[0]) { |
|
125 |
case 0: scaleOffsetList[0] = stretchs.red; |
|
126 |
break; |
|
127 |
case 1: scaleOffsetList[0] = stretchs.green; |
|
128 |
break; |
|
129 |
case 2: scaleOffsetList[0] = stretchs.blue; |
|
130 |
break; |
|
131 |
default: scaleOffsetList[0] = stretchs.red; |
|
132 |
} |
|
133 |
switch (renderBands[1]) { |
|
134 |
case 0: scaleOffsetList[1] = stretchs.red; |
|
135 |
break; |
|
136 |
case 1: scaleOffsetList[1] = stretchs.green; |
|
137 |
break; |
|
138 |
case 2: scaleOffsetList[1] = stretchs.blue; |
|
139 |
break; |
|
140 |
default: scaleOffsetList[1] = stretchs.red; |
|
141 |
} |
|
142 |
switch (renderBands[2]) { |
|
143 |
case 0: scaleOffsetList[2] = stretchs.red; |
|
144 |
break; |
|
145 |
case 1: scaleOffsetList[2] = stretchs.green; |
|
146 |
break; |
|
147 |
case 2: scaleOffsetList[2] = stretchs.blue; |
|
148 |
break; |
|
149 |
default: scaleOffsetList[2] = stretchs.red; |
|
150 |
} |
|
151 |
} |
|
109 | 152 |
|
110 | 153 |
/** |
111 | 154 |
* Obtiene el porcentaje de recorte de colas aplicado o 0 si no tiene. |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/LinearStretchEnhancementIntFilter.java | ||
---|---|---|
44 | 44 |
|
45 | 45 |
processValue(p, stretchs.gray, col, line, iBand); |
46 | 46 |
switch (iBand) { |
47 |
case 0: processValue(p, stretchs.red, col, line, iBand);
|
|
47 |
case 0: processValue(p, scaleOffsetList[0], col, line, iBand);
|
|
48 | 48 |
break; |
49 |
case 1: processValue(p, stretchs.green, col, line, iBand);
|
|
49 |
case 1: processValue(p, scaleOffsetList[1], col, line, iBand);
|
|
50 | 50 |
break; |
51 |
case 2: processValue(p, stretchs.blue, col, line, iBand);
|
|
51 |
case 2: processValue(p, scaleOffsetList[2], col, line, iBand);
|
|
52 | 52 |
break; |
53 | 53 |
} |
54 | 54 |
} |
... | ... | |
66 | 66 |
*/ |
67 | 67 |
private void processValue(int p, Stretch data, int col, int line, int iBand) { |
68 | 68 |
if(data.scale != null) { |
69 |
if (p > data.maxValue) |
|
70 |
p = (int) data.maxValue; |
|
71 |
else if (p < data.minValue) |
|
72 |
p = (int) data.minValue; |
|
73 |
|
|
69 | 74 |
for (int i = 0; i < data.scale.length; i++) { |
70 | 75 |
if(p >= data.stretchIn[i] && p <= data.stretchIn[i + 1]) |
71 | 76 |
p = (int)(((double)p) * data.scale[i] + data.offset[i]); |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/LinearStretchEnhancementShortFilter.java | ||
---|---|---|
44 | 44 |
|
45 | 45 |
processValue(p, stretchs.gray, col, line, iBand); |
46 | 46 |
switch (iBand) { |
47 |
case 0: processValue(p, stretchs.red, col, line, iBand);
|
|
47 |
case 0: processValue(p, scaleOffsetList[0], col, line, iBand);
|
|
48 | 48 |
break; |
49 |
case 1: processValue(p, stretchs.green, col, line, iBand);
|
|
49 |
case 1: processValue(p, scaleOffsetList[1], col, line, iBand);
|
|
50 | 50 |
break; |
51 |
case 2: processValue(p, stretchs.blue, col, line, iBand);
|
|
51 |
case 2: processValue(p, scaleOffsetList[2], col, line, iBand);
|
|
52 | 52 |
break; |
53 | 53 |
} |
54 | 54 |
|
... | ... | |
67 | 67 |
*/ |
68 | 68 |
private void processValue(short p, Stretch data, int col, int line, int iBand) { |
69 | 69 |
if(data.scale != null) { |
70 |
if (p > data.stretchIn[data.stretchIn.length - 1])
|
|
71 |
p = (short) data.stretchIn[data.stretchIn.length - 1];
|
|
72 |
else if (p < data.stretchIn[0])
|
|
73 |
p = (short) data.stretchIn[0];
|
|
70 |
if (p > data.maxValue)
|
|
71 |
p = (short) data.maxValue;
|
|
72 |
else if (p < data.minValue)
|
|
73 |
p = (short) data.minValue;
|
|
74 | 74 |
|
75 | 75 |
for (int i = 0; i < data.scale.length; i++) { |
76 | 76 |
if(p >= data.stretchIn[i] && p <= data.stretchIn[i + 1]) |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/LinearStretchEnhancementByteFilter.java | ||
---|---|---|
44 | 44 |
|
45 | 45 |
processValue(p, stretchs.gray, col, line, iBand); |
46 | 46 |
switch (iBand) { |
47 |
case 0: processValue(p, stretchs.red, col, line, iBand);
|
|
47 |
case 0: processValue(p, scaleOffsetList[0], col, line, iBand);
|
|
48 | 48 |
break; |
49 |
case 1: processValue(p, stretchs.green, col, line, iBand);
|
|
49 |
case 1: processValue(p, scaleOffsetList[1], col, line, iBand);
|
|
50 | 50 |
break; |
51 |
case 2: processValue(p, stretchs.blue, col, line, iBand);
|
|
51 |
case 2: processValue(p, scaleOffsetList[2], col, line, iBand);
|
|
52 | 52 |
break; |
53 | 53 |
} |
54 | 54 |
} |
... | ... | |
66 | 66 |
*/ |
67 | 67 |
private void processValue(int p, Stretch data, int col, int line, int iBand) { |
68 | 68 |
if(data.scale != null) { |
69 |
if (p > data.maxValue) |
|
70 |
p = (int) data.maxValue; |
|
71 |
else if (p < data.minValue) |
|
72 |
p = (int) data.minValue; |
|
73 |
|
|
69 | 74 |
for (int i = 0; i < data.scale.length; i++) { |
70 | 75 |
if(p >= data.stretchIn[i] && p <= data.stretchIn[i + 1]) |
71 | 76 |
p = (int)(((double)p) * data.scale[i] + data.offset[i]); |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/statistics/TailTrimDoubleFilter.java | ||
---|---|---|
96 | 96 |
result[i][0] = sampleDec[i][posInit + tailSizeList[iValue]]; |
97 | 97 |
result[i][1] = sampleDec[i][(posInit + nSamples) - tailSizeList[iValue]]; |
98 | 98 |
} |
99 |
stats.setTailTrimValue(tailPercent, result); |
|
99 |
stats.setTailTrimValue(tailPercentList[iValue], result);
|
|
100 | 100 |
} |
101 | 101 |
} |
102 | 102 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/statistics/TailTrimIntegerFilter.java | ||
---|---|---|
95 | 95 |
result[i][0] = sample[i][posInit + tailSizeList[iValue]]; |
96 | 96 |
result[i][1] = sample[i][(posInit + nSamples) - tailSizeList[iValue]]; |
97 | 97 |
} |
98 |
stats.setTailTrimValue(tailPercent, result); |
|
98 |
stats.setTailTrimValue(tailPercentList[iValue], result);
|
|
99 | 99 |
} |
100 | 100 |
} |
101 | 101 |
} |
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/statistics/TailTrimByteFilter.java | ||
---|---|---|
90 | 90 |
result[i][0] = sample[i][posInit + tailSizeList[iValue]]; |
91 | 91 |
result[i][1] = sample[i][(posInit + nSamples) - tailSizeList[iValue]]; |
92 | 92 |
} |
93 |
stats.setTailTrimValue(tailPercent, result); |
|
93 |
stats.setTailTrimValue(tailPercentList[iValue], result);
|
|
94 | 94 |
} |
95 | 95 |
} |
96 | 96 |
|
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/statistics/TailTrimFloatFilter.java | ||
---|---|---|
96 | 96 |
result[i][0] = sampleDec[i][posInit + tailSizeList[iValue]]; |
97 | 97 |
result[i][1] = sampleDec[i][(posInit + nSamples) - tailSizeList[iValue]]; |
98 | 98 |
} |
99 |
stats.setTailTrimValue(tailPercent, result); |
|
99 |
stats.setTailTrimValue(tailPercentList[iValue], result);
|
|
100 | 100 |
} |
101 | 101 |
} |
102 | 102 |
} |
Also available in: Unified diff