Data Source: images in sequence
Operation: add pixels to an array and create an average of all images on each addition
Output: stills in sequence revealing a mediated temporal perspective

non1650.jpg

global declarations and setup
int [][][] aveImg;
String files[];
PImage b;
int f, i, j, k;
 
void setup() {  
  noLoop();
  colorMode(RGB);
 
  String directory;
 
  files = new String[1];
  directory = "C:/.../sketch_image_average_stills/image_source/";
  getFileNames(directory); 
 
  if (files.length > 1) {
    b = loadImage("image_source/" + files[0]);
    size(b.width,b.height);
  }
 
  aveImg = new int[width][height][3];
}

draw
void draw() {
  if (files.length > 1) {
 
    for (f=0; f<files.length-1; f++) {
      b = loadImage("image_source/" + files[f]);
      background(b);
      println(f);
      pullImage();
      drawAverage();
    }
  }
}

read file names in source directory
void getFileNames (String fileDir) {
//http://www.exampledepot.com/egs/java.io/GetFiles.html
  File dir = new File(fileDir);
  String[] children = dir.list();
 
  if (children == null) {
    println("oops");
  } else {
    files = new String[children.length];      
 
    for (f=0; f<children.length; f++) {
      String filename = children[f];
      files[f] = filename;
    }
  }
}

add each red, green, and blue value for all pixels into array
void pullImage() {
  loadPixels();
 
  for (j=0; j<height; j++) {
    for (i=0; i<width; i++) {       
      k = j*width+i;
      aveImg[i][j][0] = aveImg[i][j][0] + int(red(pixels[k]));
      aveImg[i][j][1] = aveImg[i][j][1] + int(green(pixels[k]));
      aveImg[i][j][2] = aveImg[i][j][2] + int(blue(pixels[k]));
    }
  }
}

create an average of each pixel's color values
void drawAverage() {
 if (f > 0) {
  for (j=0; j<height; j++) {
    for (i=0; i<width; i++) {             
      k = j*width+i;   
      pixels[k] = color(aveImg [i][j][0]/f+1, aveImg [i][j][1]/f+1, aveImg [i][j][2]/f+1); 
    }
  }
 
 updatePixels();
 saveImage();
 } 
}

create filename and save image as jpg
void saveImage() {
  String fileNum;
 
  if (f < 10) { fileNum = "000" + str(f); }
  else if (f < 100) { fileNum = "00" + str(f); }
  else if (f < 1000) { fileNum = "0" + str(f); }
  else { fileNum = str(f); }  
 
  save("average_output_" + fileNum + ".jpg");
}