-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessarImagem.java
268 lines (228 loc) · 10.2 KB
/
ProcessarImagem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package pdi;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
public class ProcessarImagem {
private static BufferedImage image ;
public ProcessarImagem(String Arquivo) throws IOException {// Pega o caminho para salvar a imagem
this.image = ImageIO.read(new File(Arquivo));
}
public ProcessarImagem(BufferedImage img, double[][] gaussian) {
}
private void salvarImagem(String Salvar) throws IOException {//salva a imagem
ImageIO.write(image, "JPG", new File(Salvar));
}
private int somaTomComLimiteMinMax(int valorBandaAtual, int valorAumentoBanda){//brilho max soma
if(valorBandaAtual+valorAumentoBanda > 255){
return 255;
}else if(valorBandaAtual+valorAumentoBanda < 0){
return 0;
}else{
return valorBandaAtual+valorAumentoBanda;
}
}
private int multiplicacaoComLimiteMinMax(int valorBandaAtual, double valorAumentoBanda){
if(valorBandaAtual*valorAumentoBanda > 255){
return 255;
}else if(valorBandaAtual*valorAumentoBanda < 0){
return 0;
}else{
return (int) (valorBandaAtual*valorAumentoBanda);
}
}
public void bandaAzul(String Salvar) throws IOException {
int altura;
int largura;
for(altura = 0; altura< image.getHeight(); altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
Color azul = new Color(0, 0,cor.getBlue());
image.setRGB(altura,largura,azul.getRGB());
}
}
this.salvarImagem(Salvar);
}
public void bandaVerde(String Salvar) throws IOException {
int altura;
int largura;
for(altura = 0; altura< image.getHeight(); altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
Color verde = new Color(0, cor.getGreen(),0);
image.setRGB(altura,largura,verde.getRGB());
}
}
this.salvarImagem(Salvar);
}
public void bandaVermelho(String Salvar) throws IOException {
int altura;
int largura;
for(altura = 0; altura< image.getHeight(); altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
Color vermelho = new Color(cor.getRed(), 0,0);
image.setRGB(altura,largura,vermelho.getRGB());
}
}
this.salvarImagem(Salvar);
}
public void imagemOrigi(String Salvar) throws IOException {
int altura;
int largura;
for(altura = 0; altura< image.getHeight(); altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
Color origi = new Color(cor.getRed(),cor.getGreen(),0);
image.setRGB(altura,largura,origi.getRGB());
}
}
this.salvarImagem(Salvar);
}
public void cinzaMedio(String Salvar) throws IOException {
int altura;
int largura;
for(altura = 0; altura< image.getHeight(); altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
int somaCores = cor.getRed() + cor.getGreen() + cor.getBlue();
int media = somaCores/3;
Color cinzaMedio = new Color(media, media,media);
image.setRGB(altura,largura,cinzaMedio.getRGB());
}
}
this.salvarImagem(Salvar);
}
public void cinzaDerivado(String Salvar, String banda) throws IOException{
int altura;
int largura;
for(altura = 0; altura< image.getHeight(); altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
int valor = 0;
if(banda == "Vermelho"){
valor = cor.getRed();
}else if(banda == "Verde"){
valor = cor.getGreen();
}else if(banda == "Azul"){
valor = cor.getGreen();
}else{
throw new IllegalArgumentException("Insira um valor igual a Vermelho, Azul ou Verde");
}
Color newCor = new Color(valor, valor,valor);
image.setRGB(altura,largura,newCor.getRGB());
}
}
this.salvarImagem(Salvar);
}
public void subirTom(String Salvar, String banda, int valorSubirTom)throws IOException{
int altura;
int largura;
for(altura = 0; altura< image.getHeight(); altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
int red = banda == "Vermelho"? somaTomComLimiteMinMax(cor.getRed(), valorSubirTom) : cor.getRed();
int green = banda == "Verde"? somaTomComLimiteMinMax(cor.getGreen(), valorSubirTom) : cor.getGreen();
int blue = banda == "Azul"? somaTomComLimiteMinMax(cor.getBlue(), valorSubirTom) : cor.getBlue();
Color newCor = new Color(red, green, blue);
image.setRGB(altura,largura,newCor.getRGB());
}
}
this.salvarImagem(Salvar);
}
public void negativo(String Salvar)throws IOException{
int altura;
int largura;
for(altura = 0; altura< image.getHeight(); altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
int red = 255 - cor.getRed();
int green = 255 - cor.getGreen();
int blue = 255 - cor.getBlue();
Color neg = new Color(red, green, blue);
image.setRGB(altura,largura,neg.getRGB());
}
}
this.salvarImagem(Salvar);
}
//limiar 128
public void limiarizacao(String Salvar, int limiar) throws IOException {
int altura;
int largura;
for(altura = 0; altura< image.getHeight(); altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
int somaCores = (cor.getRed() + cor.getGreen() + cor.getBlue()) / 3 ;
Color newCor = new Color(0, 0,0);
if(somaCores > limiar){
newCor = new Color(255, 255,255);
}
image.setRGB(altura,largura,newCor.getRGB());
}
}
this.salvarImagem(Salvar);
}
public void brilhoAditivo(String Salvar, int valorSubirBrilho)throws IOException{
int altura;
int largura;
for(altura = 0; altura< image.getHeight() ;altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
int red = somaTomComLimiteMinMax(cor.getRed(), valorSubirBrilho);
int green = somaTomComLimiteMinMax(cor.getGreen(), valorSubirBrilho);
int blue = somaTomComLimiteMinMax(cor.getBlue(), valorSubirBrilho);
Color newCor = new Color(red, green,blue);
image.setRGB(altura,largura,newCor.getRGB());
}
}
this.salvarImagem(Salvar);
}
public void brilhoMultiplicativo(String Salvar, double valorMultiplicarBrilho)throws IOException{
int altura;
int largura;
for(altura = 0; altura< image.getHeight(); altura++){
for(largura = 0; largura< image.getWidth(); largura++){
int rgbInt = image.getRGB(altura,largura);
Color cor = new Color(rgbInt);
int red = multiplicacaoComLimiteMinMax(cor.getRed(), valorMultiplicarBrilho);
int green = multiplicacaoComLimiteMinMax(cor.getGreen(), valorMultiplicarBrilho);
int blue = multiplicacaoComLimiteMinMax(cor.getBlue(), valorMultiplicarBrilho);
Color newCor = new Color(red, green,blue);
image.setRGB(altura,largura,newCor.getRGB());
}
}
this.salvarImagem(Salvar);
}
public static BufferedImage media(BufferedImage imagemEntrada) {
BufferedImage imagemSaida = image.getSubimage(0, 0, image.getWidth(), image.getHeight());
int[] valoresVizinhanca = new int[9];
for (int i = 1; i < imagemEntrada.getHeight() - 1; i++) {
for (int j = 1; j < imagemEntrada.getWidth() - 1; j++) {
int aux = -1;
for (int x = j - 1; x <= j + 1; x++) {
for (int y = i - 1; y <= i + 1; y++) {
valoresVizinhanca[++aux] = new Color(imagemEntrada.getRGB(x, y)).getRed();
}
}
int media = Arrays.stream(valoresVizinhanca).sum() / 9;
int[] arrayOrdenado = Arrays.stream(valoresVizinhanca).sorted().toArray();
int mediana = arrayOrdenado[arrayOrdenado.length / 2];
Color novaCor = new Color(media, media, media);
imagemSaida.setRGB(j, i, novaCor.getRGB());
}
}
return imagemSaida;
}
}