We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › [solved] 5k jpgs > array > tif ArryOutOfBounds:0
Page Index Toggle Pages: 1
[solved] 5k jpgs > array > tif ArryOutOfBounds:0 ? (Read 334 times)
[solved] 5k jpgs > array > tif ArryOutOfBounds:0 ?
Mar 22nd, 2009, 1:47pm
 
input: maaany images (1.jpg to 5000.jpg)
what should be the output: 1.jpg, 1+2.jpg, 1+2+3.jpg... (each frame should be an overlay of 1 to 5000 images merging them to their average)

Running this I get an ArrayIndexOutOfBounds:0 Error in the marked line.
I coded this more or less blind: without much clue of processing in general and without any prove that this *could* work. If someone could proofread this he'd make me a happier person :)


void setup() {//runs once

 size(100, 100);// Set the window size in pixels
 noLoop();
 frameRate(1);//per second
}


 //vars//////
 int count = 0;
 int anzahl_bilder = 0;
 PImage akt_bild;
 int r = 0;
 int g = 0;
 int b = 0;
 float[] allr = new float[width*height];
 float[] allg = new float[width*height];
 float[] allb = new float[width*height];
 /////////////
 
 
void draw() {// frame by frame
 background(255);
 
//    if(count < 10) {            //framestopper and layering progress
//    count = count + 1;
//  } else {
//    noLoop();
//  }
 
 count = 5; //number of overlayed images (for now)
 anzahl_bilder = count;


 float[][][] alle_bilder = new float[anzahl_bilder][3][width*height]; //all_images[number of overlays][r g b][num of pixels]
 for (int bild = 0; bild < anzahl_bilder; ++bild) { //
   akt_bild = loadImage((bild+1) + ".jpg"); //load image to add (1 to x.jpg are in the data folder)
   loadPixels(); //get pixels
   for (int kanal = 0; kanal < 3; ++kanal) { // rgb choice
     for (int pixel=0; pixel < width*height; ++pixel) {// pixel "adress"
 
       if (kanal == 0) alle_bilder[bild][kanal][pixel] = (pixels[pixel] >> 16) & 0xFF; //0red    //extracting r g b to all_images
       if (kanal == 1) alle_bilder[bild][kanal][pixel] = (pixels[pixel] >> 8) & 0xFF;  //1green
       if (kanal == 2) alle_bilder[bild][kanal][pixel] = pixels[pixel] & 0xFF;         //2blue
       }
     }
   }  //und dann halt mit alle_bilder arbeiten
 
 for (int bild = 0; bild < anzahl_bilder; ++bild) {  
     for (int pixel=0; pixel < width*height; ++pixel) {// adding all images to one "ultra bright" image
        allr[pixel] = allr[pixel]+alle_bilder[bild][0][pixel]; //////////ERROR OCCURES HERE//////////////
        allg[pixel] = allg[pixel]+alle_bilder[bild][1][pixel];
        allb[pixel] = allb[pixel]+alle_bilder[bild][2][pixel];
 
     }
 }
 //color pink = color(255, 102, 204);
 for (int i = 0; i < (width*height); i++) {//calculating them down to  normal (<255) and even numbers
   r = round(allr[i]/anzahl_bilder);
   g = round(allg[i]/anzahl_bilder);
   b = round(allb[i]/anzahl_bilder);
   pixels[i] = color(r, g, b); ///drawing to pixels
 }
 updatePixels();//draw on screen
 

 
 
     saveFrame("data/merge_#####.tif");//output a snapshot
 loop();
}


btw: If this works I will do the same with sound: voice + more and more voice = noise
noise + more and more noise = silence (average of random = 0)
should be even easyier with *wav*s , right?

Oh and sry for the repost I did

edit: width and heigh are 0 nefore the setup runs %)
Page Index Toggle Pages: 1