Revision 19491

View differences:

trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/EcualizationFilter.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.datastruct.Histogram;
28
import org.gvsig.raster.datastruct.HistogramException;
28 29
import org.gvsig.raster.grid.filter.RasterFilter;
29 30
/**
30 31
 * Clase base para los filtros de ecualizaci?n de histograma.
......
33 34
 * @author Nacho Brodin (nachobrodin@gmail.com)
34 35
 */
35 36
public class EcualizationFilter extends RasterFilter {
36
	protected DatasetListStatistics	   stats         = null;
37
	protected double[]                 minBandValue	 = null;
38
	protected double[]                 maxBandValue	 = null;
39
	protected int                      nbands        = 3;
40
	protected int[]                    renderBands   = null;
41
	protected int[]                    k             = null;                   
42
	public static String[]             names         = new String[] {"ecualization"};
43
	protected Histogram                histogram     = null;
44
	protected long                     nPixels       = 0;
45
	protected int[][]                  resValues     = null;
46
	protected long[][]                 lahe          = null;
47
	protected long[][]                 laheNegative  = null;
48
	protected int                      nElements     = 0;
37
	protected DatasetListStatistics	   stats          = null;
38
	protected double[]                 minBandValue	  = null;
39
	protected double[]                 maxBandValue	  = null;
40
	protected int                      nbands         = 3;
41
	protected int[]                    renderBands    = null;
42
	protected int[]                    k              = null;                   
43
	public static String[]             names          = new String[] {"ecualization"};
44
	protected Histogram                histogram      = null;
45
	protected long                     nPixels        = 0;
46
	protected int[][]                  resValues      = null;
47
	protected long[][]                 lahe           = null;
48
	protected long[][]                 laheNegative   = null;
49
	protected int                      nElements      = 0;
50
	protected int[]                    ecualizedBands = null;
49 51
	
50 52
	/**
51 53
	 * Construye un LinearEnhancementFilter
......
78 80
		if(renderBands == null)
79 81
			renderBands = new int[]{0, 1, 2};
80 82
		
83
		ecualizedBands = (int[]) params.get("ecualizedBands");
84
		if(ecualizedBands == null)
85
			ecualizedBands = renderBands;
86
		
81 87
		height = raster.getHeight();
82 88
		width = raster.getWidth();
83 89
		nPixels = height * width;
......
95 101
		if(raster.getDataType() == IBuffer.TYPE_BYTE) {
96 102
			minBandValue = stats.getMinRGB();
97 103
			maxBandValue = stats.getMaxRGB();
98
		} else {
99
			minBandValue = stats.getMin();
100
			maxBandValue = stats.getMax();
104
		} 
105
		if(minBandValue[0] == 0 && maxBandValue[0] == 0) {
106
			minBandValue = new double[raster.getBandCount()];
107
			maxBandValue = new double[raster.getBandCount()];
108
			for (int i = 0; i < minBandValue.length; i++) {
109
				minBandValue[i] = 0;
110
				maxBandValue[i] = 255;
111
			}
112
			//minBandValue = stats.getMin();
113
			//maxBandValue = stats.getMax();
101 114
		}
102 115
		
103
		Histogram rgbHistogram = Histogram.convertHistogramToRGB(histogram);
116
		//Histogram rgbHistogram = Histogram.convertHistogramToRGB(histogram);
117
		Histogram rgbHistogram;
118
		try {
119
			rgbHistogram = Histogram.convertHistogramToRGB(raster.getHistogram());
120
		} catch (HistogramException e) {
121
			return;
122
		} catch (InterruptedException e) {
123
			return;
124
		}
104 125
		double[][] accumNormalize = Histogram.convertTableToNormalizeAccumulate(rgbHistogram.getTable());
105 126
		double[][] accumNormalizeNeg = Histogram.convertTableToNormalizeAccumulate(rgbHistogram.getNegativeTable());
106 127

  
......
128 149
	}
129 150
	
130 151
	/**
152
	 * Consulta si la ecualizaci?n est? activa para una banda o no
153
	 * @param band N?mero de banda a consultar si se ha activado la ecualizaci?n
154
	 * @return true si est? activa para esa banda y false si no lo est?.
155
	 */
156
	protected boolean ecualizationActive(int band) {
157
		for (int i = 0; i < ecualizedBands.length; i++) {
158
			if(band == ecualizedBands[i])
159
				return true;
160
		}
161
		return false;
162
	}
163
	
164
	/**
131 165
	 * Obtiene una distribuci?n de probabilidad de niveles de gris.  
132 166
	 * @param bands N?mero de bandas
133 167
	 * @param nValues Valores a distribuir. Tipicamente 255
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/EcualizationByteFilter.java
33 33
	 */
34 34
	public void process(int col, int line) {
35 35
		for (int iBand = 0; iBand < raster.getBandCount(); iBand++) {
36
			int p = (int)(raster.getElemByte(line, col, iBand) & 0xff);	
36
			int p = (int)(raster.getElemByte(line, col, iBand) & 0xff);
37
			if(!ecualizationActive(iBand)) {
38
				rasterResult.setElem(line, col, iBand, (byte)p);
39
				continue;
40
			}
41
			
37 42
			if (p > maxBandValue[renderBands[iBand]])
38 43
				p = (int) maxBandValue[renderBands[iBand]];
39 44
			else if (p < minBandValue[renderBands[iBand]])
40 45
				p = (int) minBandValue[renderBands[iBand]];
41
		
42
			long ecualizationPositive = lahe[renderBands[iBand]][p];
43
			long ecualizationNegative = laheNegative[renderBands[iBand]][nElements - p];
46

  
47
			long ecualizationPositive = lahe[renderBands[iBand]][p % histogram.getNumValues()];
48
			long ecualizationNegative = laheNegative[renderBands[iBand]][nElements - (p % histogram.getNumValues())];
44 49
			double value = ((nElements - ecualizationNegative) + ecualizationPositive) / 2;
45
			
46 50
			rasterResult.setElem(line, col, iBand, (byte)value);
47 51
		}
48 52
	}
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/enhancement/EcualizationManager.java
58 58
	 * @param IStatistics
59 59
	 * @throws FilterTypeException 
60 60
	 */
61
	public void addEcualizationFilter(IStatistics stats, int[] renderBands, Histogram hist) throws FilterTypeException {
61
	public void addEcualizationFilter(IStatistics stats, int[] renderBands, Histogram hist, int[] ecualizedBands) throws FilterTypeException {
62 62
		try {
63 63
			if (!stats.isCalculated()) {
64 64
				try {
......
72 72
				}
73 73
			}
74 74

  
75
			RasterFilter filter = createEnhancedFilter(stats, renderBands, hist);
75
			RasterFilter filter = createEnhancedFilter(stats, renderBands, hist, ecualizedBands);
76 76
			if (filter != null)
77 77
				filterList.add(filter);
78 78
		} catch (InterruptedException e) {
......
86 86
	 * @param renderBands
87 87
	 * @return
88 88
	 */
89
	public static RasterFilter createEnhancedFilter(IStatistics stats, int[] renderBands, Histogram hist) {
89
	public static RasterFilter createEnhancedFilter(IStatistics stats, int[] renderBands, Histogram hist, int[] ecualizedBands) {
90 90
		RasterFilter filter = new EcualizationByteFilter();
91 91
		if (filter != null) {
92 92
			filter.addParam("stats", stats);
93 93
			filter.addParam("renderBands", renderBands);
94 94
			filter.addParam("histogram", hist);
95
			filter.addParam("ecualizedBands", ecualizedBands);
95 96
		}
96 97
		return filter;
97 98
	}
......
129 130
	public void addFilter(Class classFilter, Params params) throws FilterTypeException {
130 131
		if (classFilter.equals(EcualizationFilter.class)) {
131 132
			int[] renderBands = { 0, 1, 2 };
133
			int[] ecualizedBands = { 0, 1, 2 };
132 134
			Histogram hist = null;
133 135
			for (int i = 0; i < params.getNumParams(); i++) {
134 136
				if (params.getParam(i).id.equals("RenderBands") && 
......
143 145
					params.getParam(i).defaultValue instanceof Histogram) {
144 146
					hist = (Histogram)params.getParam(i).defaultValue;
145 147
				}
148
				if (params.getParam(i).id.equals("EcualizedBands") &&
149
					params.getParam(i).defaultValue instanceof int[]) {
150
					ecualizedBands = (int[])params.getParam(i).defaultValue;
151
				}
146 152
			}
147 153

  
148
			addEcualizationFilter((IStatistics) filterList.getEnvParam("IStatistics"), renderBands, hist);
154
			addEcualizationFilter((IStatistics) filterList.getEnvParam("IStatistics"), renderBands, hist, ecualizedBands);
149 155
		}
150 156
	}
151 157
}
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/enhanced/ui/EnhancedDialog.java
99 99
			//Si la ventana no se puede eliminar no hacemos nada
100 100
		}
101 101
	}
102
	
103
	/**
104
	 * Obtiene la capa asociada.
105
	 * @return FLyrRasterSE
106
	 */
107
	public FLyrRasterSE getLayer() {
108
		return lyr;
109
	}
102 110

  
103 111
	/*
104 112
	 * (non-Javadoc)
......
118 126
	public void windowActivated() {}
119 127

  
120 128
	/**
121
	 * @return the lyr
122
	 */
123
	public FLyrRasterSE getLayer() {
124
		return lyr;
125
	}
126

  
127
	/**
128 129
	 * @return the filteredPreview
129 130
	 */
130 131
	public PreviewFiltering getFilteredPreview() {
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/enhanced/ui/EnhancedListener.java
122 122

  
123 123
			}
124 124
			if(((String)selectorsPanel.getEnhancedType().getSelectedItem()).equals("Equalization")) {
125
				int[] renderBands = enhancedDialog.getLayer().getRender().getRenderBands();
126
				String values = "";
127
				for (int i = 0; i < renderBands.length; i++) 
128
					values += renderBands[i] + " ";
129
				values = values.trim();
125 130
				Params params = new Params();
126 131
				params.setParam("Histogram", graphicsPanel.getHistogram(), -1, null);
127
				params.setParam("RenderBands", "0 1 2", -1, null);
132
				params.setParam("RenderBands", values, -1, null);
133
				params.setParam("EcualizedBands", new int[]{0, 1, 2}, -1, null);
128 134
				filteredPreview.addNewParam("ecualization", params, EcualizationFilter.class);
129 135
			}
130 136
			if(((String)selectorsPanel.getEnhancedType().getSelectedItem()).equals("Square-root")) {

Also available in: Unified diff