Revision 5497 trunk/extensions/extRasterTools/src/org/gvsig/rasterTools/brightnessContrast/filter/HistogramImageFilter.java

View differences:

HistogramImageFilter.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19

  
1 20
package org.gvsig.rasterTools.brightnessContrast.filter;
2 21

  
3 22
import java.awt.Image;
......
2 21
import java.awt.image.BufferedImage;
22
import java.util.Vector;
3 23

  
......
18 38
	/**
19 39
	 * Matriz donde se van a almacenar los histogramas.
20 40
	 */
21
	int histoRed[];
22
	int histoGreen[];
23
	int histoBlue[];
41
	int histoRed[] = new int[256];
42
	int histoGreen[] =  new int[256];
43
	int histoBlue[] = new int[256];
24 44
	
45
	
25 46
	/**
26 47
	 * Constructor
27 48
	 *
......
33 54
	}
34 55
	
35 56
	public void pre(){
57
		this.exec=true;
36 58
		this.image = (Image) params.get("raster");
37
		this.imgWidth = image.getWidth(null);
38
		this.imgHeight = image.getHeight(null);
59
		this.width = image.getWidth(null);
60
		this.height = image.getHeight(null);
39 61
		
62
		for(int i = 0 ; i <= 255 ; i++){
63
			histoRed[i]= 0; 
64
			histoGreen[i] = 0;
65
			histoBlue[i] = 0;
66
		}
67
		
40 68
		super.pre();
41 69
	}
42 70
	
43 71
	
44 72
	public void post() {
45
		// TODO Auto-generated method stub
46

  
47 73
	}
48 74

  
49 75
	public void process(int x, int y) {
50 76
		int px = ((BufferedImage) image).getRGB(x, y);
51 77
		int px3[] = {(px & 0xff0000) >> 16, (px & 0xff00) >> 8, (px & 0xff)};
52 78
		
53
		this.histoRed[px3[0]]++;  		//Histograma para la banda R
54
		this.histoGreen[px3[1]]++;  	//Histograma para la banda G
55
		this.histoBlue[px3[2]]++;  		//Histograma para la banda B
56
		
57

  
79
		this.histoRed[px3[0]]+=1;  		//Histograma para la banda R
80
		this.histoGreen[px3[1]]+=1;  	//Histograma para la banda G
81
		this.histoBlue[px3[2]]+=1;  	//Histograma para la banda B
82
		pixel++;						//Cuenta de los pixels de la imagen
58 83
	}
59 84

  
60 85
	/**
......
67 92
		int suma = 0;
68 93
		
69 94
		for (int i = 1 ; i <= 255 ; i++){
70
			suma += vector[i];
95
			suma += vector[i]*i;
71 96
		}
72
		media = suma/255;
97
		media = suma/pixel;
73 98
		
74 99
		return media;
75 100
	}
76 101
	
102
	public int getPixel(){
103
		return this.pixel;
104
	}
77 105
	
78 106
	public void processLine(int y) {
79 107
		// TODO Auto-generated method stub
......
96 124
        }
97 125
	}
98 126
	
127
	/**
128
	 * Metodos para acceder al los valores medios de brillo para cada banda
129
	 * @return Media de brillo para la banda de color correspondiente.
130
	 */
99 131
	
132
	public int getMediaRed(){
133
		return calculaMedia(this.histoRed);
134
	}
135

  
136
	public int getMediaGreen(){
137
		return calculaMedia(this.histoGreen);
138
	}
139
	
140
	public int getMediaBlue(){
141
		return calculaMedia(this.histoBlue);
142
	}
143
	
144
	
100 145
	/**
101 146
	 * Metodos para acceder desde fuera a los histogramas calculados por el filtro
102 147
	 * @return Histogramas de cada una de las bandas de color.
......
113 158
		return (Object) this.histoBlue;
114 159
	}
115 160
	
116
	/**
117
	 * Metodos para acceder al los valores medios de brillo para cada banda
118
	 * @return Media de brillo para la banda de color correspondiente.
119
	 */
120 161
	
121
	int mediaRed(){
122
		return calculaMedia(this.histoRed);
123
	}
124

  
125
	int mediaGreen(){
126
		return calculaMedia(this.histoGreen);
127
	}
128
	
129
	int mediaBlue(){
130
		return calculaMedia(this.histoBlue);
131
	}
132 162
}

Also available in: Unified diff