Revision 22393

View differences:

trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/correction/MedianFloatFilter.java
48 48
	 * @see org.gvsig.raster.grid.filter.correction.MedianFilter#process(int, int)
49 49
	 */
50 50
	public void process(int col, int line) {
51
//	 El lado de la ventana debe ser positivo e impar.
52
		ladoVentana = Math.abs(ladoVentana);
53
		if (ladoVentana % 2 == 0)
54
			ladoVentana++;
55
		int tamVentana = ladoVentana * ladoVentana;
56
		int semiLado = (ladoVentana - 1) >> 1;
51
		float[] ventana = new float[sizeWindow];
57 52

  
58
		float[] ventana = new float[tamVentana];
59

  
60 53
		// Obtener el vector con la ventanas de muestras
61 54
		for (int band = 0; band < raster.getBandCount(); band++) {
62 55
			int k = 0;
63
			for (int i = -semiLado; i <= semiLado; i++)
64
				for (int j = -semiLado; j <= semiLado; j++) {
56
			for (int i = -halfSide; i <= halfSide; i++)
57
				for (int j = -halfSide; j <= halfSide; j++) {
65 58
					if ((col + i >= 0) && (line + j >= 0) && (col + i < width) && (line + j < height)) {
66 59
						ventana[k] = raster.getElemFloat(line + j, col + i, band);
67 60
						k++;
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/correction/MedianDoubleFilter.java
29 29
 * @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
30 30
 */
31 31
public class MedianDoubleFilter extends MedianFilter {
32

  
32
	private double[] window = null;
33
	
33 34
	public MedianDoubleFilter(){
34 35
		super();
35 36
	}
......
40 41
	 */
41 42
	public void pre() {
42 43
		super.pre();
44
		window = new double[sizeWindow];
43 45
		rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_DOUBLE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
44 46
	}
45 47

  
......
48 50
	 * @see org.gvsig.raster.grid.filter.correction.MedianFilter#process(int, int)
49 51
	 */
50 52
	public void process(int col, int line) {
51
//	 El lado de la ventana debe ser positivo e impar.
52
		ladoVentana = Math.abs(ladoVentana);
53
		if (ladoVentana % 2 == 0)
54
			ladoVentana++;
55
		int tamVentana = ladoVentana * ladoVentana;
56
		int semiLado = (ladoVentana - 1) >> 1;
57

  
58
		double[] ventana = new double[tamVentana];
59

  
60 53
		// Obtener el vector con la ventanas de muestras
61 54
		for (int band = 0; band < raster.getBandCount(); band++) {
62 55
			int k = 0;
63
			for (int i = -semiLado; i <= semiLado; i++)
64
				for (int j = -semiLado; j <= semiLado; j++) {
56
			for (int i = -halfSide; i <= halfSide; i++)
57
				for (int j = -halfSide; j <= halfSide; j++) {
65 58
					if ((col + i >= 0) && (line + j >= 0) && (col + i < width) && (line + j < height)) {
66
						ventana[k] = raster.getElemDouble(line + j, col + i, band);
59
						window[k] = raster.getElemDouble(line + j, col + i, band);
67 60
						k++;
68 61
					}
69 62
				}
70 63
			// Ordenar los valores de las ventanas, se supone que usa quickSort.
71
			Arrays.sort(ventana, 0, k);
64
			Arrays.sort(window, 0, k);
72 65

  
73 66
			// Extraer los elementos centrales y asignarselos al pixel (x,y)
74
			rasterResult.setElem(line, col, band, ventana[k >> 1]);
67
			rasterResult.setElem(line, col, band, window[k >> 1]);
75 68
		}
76 69
	}
77 70

  
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/correction/MedianIntegerFilter.java
29 29
 * @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
30 30
 */
31 31
public class MedianIntegerFilter extends MedianFilter {
32

  
32
	private int[] window = null;
33
	
33 34
	public MedianIntegerFilter(){
34 35
		super();
35 36
	}
......
40 41
	 */
41 42
	public void pre() {
42 43
		super.pre();
44
		window = new int[sizeWindow];
43 45
		rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_INT, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
44 46
	}
45 47

  
......
48 50
	 * @see org.gvsig.raster.grid.filter.correction.MedianFilter#process(int, int)
49 51
	 */
50 52
	public void process(int col, int line) {
51
		// El lado de la ventana debe ser positivo e impar.
52
		ladoVentana = Math.abs(ladoVentana);
53
		if (ladoVentana % 2 == 0)
54
			ladoVentana++;
55
		int tamVentana = ladoVentana * ladoVentana;
56
		int semiLado = (ladoVentana - 1) >> 1;
57

  
58
		int[] ventana = new int[tamVentana];
59

  
60 53
		// Obtener el vector con la ventanas de muestras
61 54
		for (int band = 0; band < raster.getBandCount(); band++) {
62 55
			int k = 0;
63
			for (int i = -semiLado; i <= semiLado; i++)
64
				for (int j = -semiLado; j <= semiLado; j++) {
56
			for (int i = -halfSide; i <= halfSide; i++)
57
				for (int j = -halfSide; j <= halfSide; j++) {
65 58
					if ((col + i >= 0) && (line + j >= 0) && (col + i < width) && (line + j < height)) {
66
						ventana[k] = raster.getElemInt(line + j, col + i, band) & 0xff;
59
						window[k] = raster.getElemInt(line + j, col + i, band) & 0xff;
67 60
						k++;
68 61
					}
69 62
				}
70 63
			// Ordenar los valores de las ventanas, se supone que usa quickSort.
71
			Arrays.sort(ventana, 0, k);
64
			Arrays.sort(window, 0, k);
72 65

  
73 66
			// Extraer los elementos centrales y asignarselos al pixel (x,y)
74
			rasterResult.setElem(line, col, band, (int) ventana[k >> 1]);
67
			rasterResult.setElem(line, col, band, (int) window[k >> 1]);
75 68
		}
76 69
	}
77 70

  
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/correction/MedianFilter.java
31 31
	/**
32 32
	 * Variable para guardar el lado de la ventana de filtrado
33 33
	 */
34
	protected int                   ladoVentana		= 0;
34
	protected int                   sideWindow		= 0;
35
	protected int                   sizeWindow      = 0;
36
	protected int                   halfSide        = 0;
35 37

  
36 38

  
37 39
	public MedianFilter() {
......
48 50
		raster = (RasterBuffer) params.get("raster");
49 51
		height = raster.getHeight();
50 52
		width = raster.getWidth();
51
		ladoVentana = ((Integer) params.get("ladoVentana")).intValue();
53
		sideWindow = ((Integer) params.get("ladoVentana")).intValue();
54
		
55
		//El lado de la ventana debe ser positivo e impar.
56
		sideWindow = Math.abs(sideWindow);
57
		if (sideWindow % 2 == 0)
58
			sideWindow++;
59
		sizeWindow = sideWindow * sideWindow;
60
		halfSide = (sideWindow - 1) >> 1;
52 61
	}
53 62

  
54 63
	/*
......
112 121
	public Params getUIParams(String nameFilter) {
113 122
		Params params = new Params();
114 123
		params.setParam("LadoVentana",
115
				new Integer(ladoVentana),
124
				new Integer(sideWindow),
116 125
				Params.SLIDER,
117 126
				new String[] {"1", "7", "0", "1", "25" }); //min, max, valor defecto, intervalo peque?o, intervalo grande;
118 127
		return params;
......
124 133
	 */
125 134
	public void process(int x, int y) {
126 135
	}
136
	
137
	/**
138
	 * Obtiene el tama?o del lado de la ventana
139
	 * @return entero que representa el tama?o del lado de la 
140
	 * ventana en p?xeles
141
	 */
142
	public int getSideWindow() {
143
		return sideWindow;
144
	}
127 145
}
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/correction/MedianShortFilter.java
29 29
 * @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
30 30
 */
31 31
public class MedianShortFilter extends MedianFilter {
32

  
32
	private	short[] window = null;
33
	
33 34
	public MedianShortFilter(){
34 35
		super();
35 36
	}
......
40 41
	 */
41 42
	public void pre() {
42 43
		super.pre();
44
		window = new short[sideWindow];
43 45
		rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_SHORT, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
44 46
	}
45 47

  
......
48 50
	 * @see org.gvsig.raster.grid.filter.correction.MedianFilter#process(int, int)
49 51
	 */
50 52
	public void process(int col, int line) {
51
		// El lado de la ventana debe ser positivo e impar.
52
		ladoVentana = Math.abs(ladoVentana);
53
		if (ladoVentana % 2 == 0)
54
			ladoVentana++;
55
		int tamVentana = ladoVentana * ladoVentana;
56
		int semiLado = (ladoVentana - 1) >> 1;
57

  
58
		short[] ventana = new short[tamVentana];
59

  
60 53
		// Obtener el vector con la ventanas de muestras
61 54
		for (int band = 0; band < raster.getBandCount(); band++) {
62 55
			int k = 0;
63
			for (int i = -semiLado; i <= semiLado; i++)
64
				for (int j = -semiLado; j <= semiLado; j++) {
56
			for (int i = -halfSide; i <= halfSide; i++)
57
				for (int j = -halfSide; j <= halfSide; j++) {
65 58
					if ((col + i >= 0) && (line + j >= 0) && (col + i < width) && (line + j < height)) {
66
						ventana[k] = raster.getElemShort(line + j, col + i, band);
59
						window[k] = raster.getElemShort(line + j, col + i, band);
67 60
						k++;
68 61
					}
69 62
				}
70 63
			// Ordenar los valores de las ventanas, se supone que usa quickSort.
71
			Arrays.sort(ventana, 0, k);
64
			Arrays.sort(window, 0, k);
72 65

  
73 66
			// Extraer los elementos centrales y asignarselos al pixel (x,y)
74
			rasterResult.setElem(line, col, band, ventana[k >> 1]);
67
			rasterResult.setElem(line, col, band, window[k >> 1]);
75 68
		}
76 69
	}
77 70

  
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/correction/MedianListManager.java
76 76
		if (rf instanceof MedianFilter) {
77 77
			filterList.add("filter.median.active=true");
78 78
			MedianFilter medianFilter = (MedianFilter) rf;
79
			filterList.add("filter.median.ladoVentana=" + medianFilter.ladoVentana);
79
			filterList.add("filter.median.ladoVentana=" + medianFilter.getSideWindow());
80 80
		}
81 81

  
82 82
		return filterList;
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/correction/MedianByteFilter.java
29 29
 * @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
30 30
 */
31 31
public class MedianByteFilter extends MedianFilter {
32
	private int[] window = null;
32 33

  
33 34
	public MedianByteFilter() {
34 35
		super();
......
40 41
	 */
41 42
	public void pre() {
42 43
		super.pre();
44
		window = new int[sizeWindow];
43 45
		rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
44 46
	}
45 47

  
......
48 50
	 * @see org.gvsig.raster.grid.filter.correction.MedianFilter#process(int, int)
49 51
	 */
50 52
	public void process(int col, int line) {
51
//	 El lado de la ventana debe ser positivo e impar.
52
		ladoVentana = Math.abs(ladoVentana);
53
		if (ladoVentana % 2 == 0)
54
			ladoVentana++;
55
		int tamVentana = ladoVentana * ladoVentana;
56
		int semiLado = (ladoVentana - 1) >> 1;
57

  
58
		int[] ventana = new int[tamVentana];
59

  
60 53
		// Obtener el vector con la ventanas de muestras
61 54
		for (int band = 0; band < raster.getBandCount(); band++) {
62 55
			int k = 0;
63
			for (int i = -semiLado; i <= semiLado; i++)
64
				for (int j = -semiLado; j <= semiLado; j++) {
56
			for (int i = -halfSide; i <= halfSide; i++)
57
				for (int j = -halfSide; j <= halfSide; j++) {
65 58
					if ((col + i >= 0) && (line + j >= 0) && (col + i < width) && (line + j < height)) {
66
						ventana[k] = raster.getElemByte(line + j, col + i, band) & 0xff;
59
						window[k] = raster.getElemByte(line + j, col + i, band) & 0xff;
67 60
						k++;
68 61
					}
69 62
				}
70 63
			// Ordenar los valores de las ventanas, se supone que usa quickSort.
71
			Arrays.sort(ventana, 0, k);
64
			Arrays.sort(window, 0, k);
72 65

  
73 66
			// Extraer los elementos centrales y asignarselos al pixel (x,y)
74
			rasterResult.setElem(line, col, band, (byte) ventana[k >> 1]);
67
			rasterResult.setElem(line, col, band, (byte) window[k >> 1]);
75 68
		}
76 69
	}
77 70

  

Also available in: Unified diff