Revision 2438 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/grid/filter/convolution/ConvolutionFilter.java

View differences:

ConvolutionFilter.java
22 22
package org.gvsig.raster.impl.grid.filter.convolution;
23 23

  
24 24
import org.gvsig.fmap.dal.coverage.datastruct.Params;
25
import org.gvsig.fmap.dal.coverage.exception.FilterAddException;
25 26
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter;
26
import org.gvsig.raster.impl.buffer.RasterBuffer;
27 27
import org.gvsig.raster.impl.datastruct.Kernel;
28 28
import org.gvsig.raster.impl.store.ParamsImpl;
29 29

  
......
35 35

  
36 36
public class ConvolutionFilter extends BaseRasterFilter {
37 37

  
38
	public static String[]     names        = new String[] {"media", "pasobajo", "sharpen", "gauss", "personalizado"};
39
	public int                 ladoVentana  = 0;
40
	protected Kernel           kernel       = null;
38
	public static String[]     names           = new String[] {"media", "pasobajo", "sharpen", "gauss", "personalizado"};
39
	public int                 ladoVentana     = 0;
40
	protected Kernel           kernel          = null;
41 41

  
42 42
	/** Tipos de filtros de convolucion */
43
	public static final int TYPE_MEDIA  = 0;
44
	public static final int TYPE_LOWPASS  = 1;
45
	public static final int TYPE_HIGHPASS  = 2;
46
	public static final int TYPE_GAUSS  = 3;
47
	public static final int TYPE_OTHER  = 4;
43
	public static final int    TYPE_MEDIA      = 0;
44
	public static final int    TYPE_LOWPASS    = 1;
45
	public static final int    TYPE_HIGHPASS   = 2;
46
	public static final int    TYPE_GAUSS      = 3;
47
	public static final int    TYPE_OTHER      = 4;
48 48

  
49 49
	/**Definicion de los filtros basicos */
50
	static final double gauss3x3[][]= {{1,4,1},{4,12,4},{1,4,1}};
51
	static final double gauss5x5[][]= {{1,2,3,2,1},{2,7,11,7,2},{3,11,17,11,3},{2,7,11,7,2},{1,2,3,2,1}};
52
	static final double gauss7x7[][]= {{1,1,2,2,2,1,1},{1,2,2,4,2,2,1},{2,2,4,8,4,2,2},{2,4,8,16,8,4,2},{2,2,4,8,4,2,2},{1,2,2,4,2,2,1},{1,1,2,2,2,1,1}};
53
	static final double gauss7x7aux[][]= {{0,0,0.0003,0.0006,0.0003,0,0},{0,0.0011,0.0079,0.0153,0.0079,0.0011,0},{0.0003,0.0079,0.0563,0.1082,0.0563,0.0079,0.0003},{0.0006,0.0153,0.1082,0.2079,0.1082,0.0153,0.0006},{0.0003,0.0079,0.0563,0.1082,0.0563,0.0079,0.0003},{0,0.0011,0.0079,0.0153,0.0079,0.0011,0},{0,0,0.0003,0.0006,0.0003,0,0}};
54
	static final double lowpass3x3[][]= {{0,1,0},{1,6,1},{0,1,0}};
55
	static final double lowpass5x5[][]= {{1,1,1,1,1},{1,4,4,4,1},{1,4,12,4,1},{1,4,4,4,1},{1,1,1,1,1}};
56
	static final double media3x3[][]={{1,1,1},{1,1,1},{1,1,1}};
57
	static final double media5x5[][]={{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1}};
58
	static final double media7x7[][]={{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1}};
59
	static final double highpass3x3[][]= {{-1,-1,-1},{-1,9,-1},{-1,-1,-1}};
50
	static final double        gauss3x3[][]    = {{1,4,1},{4,12,4},{1,4,1}};
51
	static final double        gauss5x5[][]    = {{1,2,3,2,1},{2,7,11,7,2},{3,11,17,11,3},{2,7,11,7,2},{1,2,3,2,1}};
52
	static final double        gauss7x7[][]    = {{1,1,2,2,2,1,1},{1,2,2,4,2,2,1},{2,2,4,8,4,2,2},{2,4,8,16,8,4,2},{2,2,4,8,4,2,2},{1,2,2,4,2,2,1},{1,1,2,2,2,1,1}};
53
	static final double        gauss7x7aux[][] = {{0,0,0.0003,0.0006,0.0003,0,0},{0,0.0011,0.0079,0.0153,0.0079,0.0011,0},{0.0003,0.0079,0.0563,0.1082,0.0563,0.0079,0.0003},{0.0006,0.0153,0.1082,0.2079,0.1082,0.0153,0.0006},{0.0003,0.0079,0.0563,0.1082,0.0563,0.0079,0.0003},{0,0.0011,0.0079,0.0153,0.0079,0.0011,0},{0,0,0.0003,0.0006,0.0003,0,0}};
54
	static final double        lowpass3x3[][]  = {{0,1,0},{1,6,1},{0,1,0}};
55
	static final double        lowpass5x5[][]  = {{1,1,1,1,1},{1,4,4,4,1},{1,4,12,4,1},{1,4,4,4,1},{1,1,1,1,1}};
56
	static final double        media3x3[][]    = {{1,1,1},{1,1,1},{1,1,1}};
57
	static final double        media5x5[][]    = {{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1}};
58
	static final double        media7x7[][]    = {{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1},{1,1,1,1,1,1,1}};
59
	static final double        highpass3x3[][] = {{-1,-1,-1},{-1,9,-1},{-1,-1,-1}};
60 60

  
61
	static final Kernel kGauss3x3 = new Kernel(gauss3x3,34);
62
	static final Kernel kGauss5x5 = new Kernel(gauss5x5,121);
63
	static final Kernel kGauss7x7 = new Kernel (gauss7x7aux);
64
	static final Kernel kLowpass3x3 = new Kernel(lowpass3x3,10);
65
	static final Kernel kLowpass5x5 = new Kernel(lowpass5x5);
66
	static final Kernel kMedia3x3 = new  Kernel(media3x3,9);
67
	static final Kernel kMedia5x5 = new Kernel (media5x5,25);
68
	static final Kernel kMedia7x7 = new Kernel (media7x7,49);
69
	static final Kernel kHighpass3x3 = new Kernel (highpass3x3);
70
	private int			operator = 0;
71
	private double      agudeza = 1;         
61
	static final Kernel        kGauss3x3       = new Kernel(gauss3x3,34);
62
	static final Kernel        kGauss5x5       = new Kernel(gauss5x5,121);
63
	static final Kernel        kGauss7x7       = new Kernel (gauss7x7aux);
64
	static final Kernel        kLowpass3x3     = new Kernel(lowpass3x3,10);
65
	static final Kernel        kLowpass5x5     = new Kernel(lowpass5x5);
66
	static final Kernel        kMedia3x3       = new  Kernel(media3x3,9);
67
	static final Kernel        kMedia5x5       = new Kernel (media5x5,25);
68
	static final Kernel        kMedia7x7       = new Kernel (media7x7,49);
69
	static final Kernel        kHighpass3x3    = new Kernel (highpass3x3);
70
	private int			       operator        = 0;
71
	private double             agudeza         = 1; 
72 72

  
73

  
74

  
75

  
76 73
	/** Filtro de Convolucion*/
77 74
	public ConvolutionFilter() {
78 75
		super();
......
96 93
		return 0;
97 94
	}
98 95

  
99
	public Object getResult(String name) {
100
		if (name.equals("raster")) {
101
			if (!exec)
102
				return this.raster;
103
			return this.rasterResult;
104
		}
105
		return null;
106
	}
107

  
108

  
109 96
	public void post() {
110 97
		//	En caso de que nadie apunte a raster, se liberara su memoria.
111 98
		raster = null;
112 99

  
113 100
	}
114 101

  
115
	public void pre() {
116
		exec = true;
117
		raster = (RasterBuffer) params.get("raster");
118
		height = raster.getHeight();
119
		width = raster.getWidth();
102
	public void pre() throws FilterAddException {
103
		super.pre();
104
		
120 105
		ladoVentana = ((Integer) params.get("ladoVentana")).intValue();
121 106
		if(params.get("Agudeza") != null)
122 107
			agudeza = ((Double) params.get("Agudeza")).doubleValue();

Also available in: Unified diff