Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///// motion detector with gradient mapper shifting each frame /////
- PImage[] img;
- int imgNum=19; ///// change number of images to process
- PImage gradient;
- color[] arrayGradient= new color[256];
- int counter=0; ///// counter for the gradient shifts;
- float r1, g1, b1, lum1;
- float r2, g2, b2, lum2;
- float sensi=10; ////// change this to set sensitivity
- void setup(){
- frameRate(10000);
- img= new PImage[imgNum];
- size(1440,750); ///// change size
- //////////////////////////////////////////setup gradient img to an array of colors
- gradient=loadImage("gradient896.png");
- gradient.loadPixels();
- ////////////////////////////////////////////////////////////////
- }
- void draw(){
- for (int k=1; k<img.length-1;k++){ ///// change k's starting position to correspond to the one of the first img of the batch
- loadFrame(k);
- loadFrame(k+1);
- setupGradient();
- detectingMotion(k);
- savingFrame(k);
- println("--- ^_^ ---> just saved frame "+(k+1));
- background(255);
- }
- exit();
- println("finisshhhissimo");
- }
- void loadFrame(int Nmbr){
- img[Nmbr] = loadImage(nf(Nmbr,4)+".png"); // -----Change name of images to pixel sort. Now is "001.tif"
- img[Nmbr].loadPixels();
- }
- void setupGradient(){
- for (int i=0; i<arrayGradient.length; i++){
- arrayGradient[i] = gradient.pixels[(i+counter)%arrayGradient.length];
- }
- counter++;
- }
- void detectingMotion(int Nmbr){
- for (int i=0; i<img[Nmbr].pixels.length;i++){
- r1= (img[Nmbr].pixels[i]>>16) & 0xFF;
- g1= (img[Nmbr].pixels[i]>>8) & 0xFF;
- b1= (img[Nmbr].pixels[i]) & 0xFF;
- lum1= 0.299*r1 + 0.587*g1 + 0.114 *b1;
- r2= (img[Nmbr+1].pixels[i]>>16) & 0xFF;
- g2= (img[Nmbr+1].pixels[i]>>8) & 0xFF;
- b2= (img[Nmbr+1].pixels[i]) & 0xFF;
- lum2= 0.299*r2 + 0.587*g2 + 0.114 *b2;
- if ((lum2<(lum1-sensi))||(lum2>(lum1+sensi))){
- img[Nmbr+1].pixels[i]=arrayGradient[round(lum2)];
- }
- }
- img[Nmbr+1].updatePixels();
- }
- void savingFrame(int Nmbr){
- image(img[Nmbr+1],0,0);
- save("newframes/"+nf(Nmbr+1,4)+".png"); // --------------Change name of newly sorted images and the folder to put them in. Now is "newFrames/001.tif"
- img[Nmbr]=null;
- img[Nmbr+1]=null;
- }
Add Comment
Please, Sign In to add comment