Guest User

Untitled

a guest
Sep 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1.  
  2. ///// motion detector with gradient mapper shifting each frame /////
  3.  
  4.  
  5. PImage[] img;
  6. int imgNum=19; ///// change number of images to process
  7.  
  8. PImage gradient;
  9. color[] arrayGradient= new color[256];
  10. int counter=0; ///// counter for the gradient shifts;
  11.  
  12. float r1, g1, b1, lum1;
  13. float r2, g2, b2, lum2;
  14. float sensi=10; ////// change this to set sensitivity
  15.  
  16. void setup(){
  17. frameRate(10000);
  18. img= new PImage[imgNum];
  19. size(1440,750); ///// change size
  20.  
  21. //////////////////////////////////////////setup gradient img to an array of colors
  22. gradient=loadImage("gradient896.png");
  23. gradient.loadPixels();
  24. ////////////////////////////////////////////////////////////////
  25. }
  26.  
  27. void draw(){
  28. 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
  29. loadFrame(k);
  30. loadFrame(k+1);
  31. setupGradient();
  32. detectingMotion(k);
  33. savingFrame(k);
  34. println("--- ^_^ ---> just saved frame "+(k+1));
  35. background(255);
  36. }
  37. exit();
  38. println("finisshhhissimo");
  39.  
  40. }
  41.  
  42. void loadFrame(int Nmbr){
  43. img[Nmbr] = loadImage(nf(Nmbr,4)+".png"); // -----Change name of images to pixel sort. Now is "001.tif"
  44. img[Nmbr].loadPixels();
  45. }
  46.  
  47. void setupGradient(){
  48. for (int i=0; i<arrayGradient.length; i++){
  49. arrayGradient[i] = gradient.pixels[(i+counter)%arrayGradient.length];
  50. }
  51. counter++;
  52. }
  53.  
  54. void detectingMotion(int Nmbr){
  55. for (int i=0; i<img[Nmbr].pixels.length;i++){
  56. r1= (img[Nmbr].pixels[i]>>16) & 0xFF;
  57. g1= (img[Nmbr].pixels[i]>>8) & 0xFF;
  58. b1= (img[Nmbr].pixels[i]) & 0xFF;
  59. lum1= 0.299*r1 + 0.587*g1 + 0.114 *b1;
  60.  
  61. r2= (img[Nmbr+1].pixels[i]>>16) & 0xFF;
  62. g2= (img[Nmbr+1].pixels[i]>>8) & 0xFF;
  63. b2= (img[Nmbr+1].pixels[i]) & 0xFF;
  64. lum2= 0.299*r2 + 0.587*g2 + 0.114 *b2;
  65.  
  66. if ((lum2<(lum1-sensi))||(lum2>(lum1+sensi))){
  67. img[Nmbr+1].pixels[i]=arrayGradient[round(lum2)];
  68.  
  69. }
  70. }
  71. img[Nmbr+1].updatePixels();
  72. }
  73.  
  74.  
  75. void savingFrame(int Nmbr){
  76. image(img[Nmbr+1],0,0);
  77. 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"
  78. img[Nmbr]=null;
  79. img[Nmbr+1]=null;
  80. }
Add Comment
Please, Sign In to add comment