forked from JaredKoester/chromatic-aberration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageAggregator.java
68 lines (53 loc) · 1.44 KB
/
ImageAggregator.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
package test;
import java.util.Random;
import javax.imageio.ImageIO;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.*;
public class ImageAggregator {
public static void main(String[] args){
new ImageAggregator(args);
}
public ImageAggregator(String[] args){
build(args);
}
public void build(String[] args) {
BufferedImage[] imageArr = new BufferedImage[args.length];
for (int i = 0; i < args.length; i++){
BufferedImage image = null;
try {
image = ImageIO.read(new File((String)args[i]));
} catch (IOException e) {
System.out.println(e);
}
imageArr[i] = image;
}
int w = imageArr[0].getWidth();
int h = imageArr[0].getHeight();
BufferedImage combined = new BufferedImage(w,h, BufferedImage.TYPE_INT_ARGB);
// width and height start from the top left
for (int ww = 0; ww<w; ww++){
for (int hh = 0; hh<h; hh++){
int r = 0;
int g = 0;
int b = 0;
for (int i = 0; i <imageArr.length; i++){
Color pixel = new Color(imageArr[i].getRGB(ww,hh));
r += pixel.getRed();
g += pixel.getGreen();
b += pixel.getBlue();
}
r = r/imageArr.length;
g = g/imageArr.length;
b = b/imageArr.length;
Color finalPixel = new Color(r,g,b);
combined.setRGB(ww,hh, finalPixel.getRGB());
}
}
try {
File outputfile = new File("saved.png");
ImageIO.write(combined, "png", outputfile);
} catch (IOException e) {
}
}
}