import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
public class Main {
static BufferedImage average(BufferedImage[] images) {
BufferedImage average = new BufferedImage(images[0].getWidth(), images[0].getHeight(),
BufferedImage.TYPE_BYTE_GRAY);
WritableRaster raster = average.getRaster().createCompatibleWritableRaster();
for (int k = 0; k < images[0].getHeight(); ++k) {
for (int j = 0; j < images[0].getWidth(); ++j) {
float sum = 0.0f;
for (int i = 0; i < images.length; ++i) {
sum = sum + images[i].getRaster().getSample(j, k, 0);
}
raster.setSample(j, k, 0, Math.round(sum / images.length));
}
}
average.setData(raster);
return average;
}
}