PImage b, c; float x,y; // variables for position float last_x, last_y, next_x, next_y; float r, theta, curr_r; // variables for sacaddic motion float last_z, z, curr_z; float t; static float d_t=1.0/24.0; static float saccade_length = 2.0; float j; static float rest_length = 1.0; static int SACCADE = 0; static int RECOVER = 1; static int mode; float next_mode; int win_width; int win_height; boolean toggleShow = false; // Set to 4 for 1/4 size Preview static int DIV = 1; // variables for logging of timing String outpath="output\\01_06_western_landscape\\"; PrintWriter output; static boolean writeToFile=false; void setup() { //size(screen.width/DIV, screen.height/DIV);//, 800); size(1280, 720); background(0); stroke(255); noFill(); rectMode(CENTER); //b=loadImage("C:\\Swap\\Photos\\03_washington dc bedroom 2.jpg"); // b=loadImage("C:\\Swap\\Photos\\01_06_western landscape.jpg"); //b=loadImage("/Users/rtwomey/Pictures/scavenging/industry/akron works 1907 6a34570u.jpg"); //b=loadImage("F:\\Users\\rtwomey\\Pictures\\scavenging\\industry\\akron works 1907 6a34570u.jpg"); //b=loadImage("F:\\Users\\rtwomey\\Pictures\\scavenging\\industry\\bethlehem steel works3.jpg"); //b=loadImage("F:\\Users\\rtwomey\\Pictures\\scavenging\\infrastructure\\HooverDam2009.jpg"); b=loadImage("F:\\Users\\rtwomey\\Pictures\\scavenging\\katrina_new_orleans.jpg"); win_height=int(b.height*0.4/DIV); win_width=int(b.width*0.4/DIV); j=0; x=0; y=random((b.height-win_height)*0.3, (b.height-win_height)*0.7); last_x=x; last_y=y; last_z=0.25; z=random(0.25, 1.1); r=random(30/z, 80/z)/DIV; t=saccade_length+0.1; mode=1; theta=(TWO_PI+HALF_PI*random(-0.95, 0.95))%TWO_PI; frameRate(24); if(writeToFile) { // setup up timing log file output = createWriter(outpath+"timing.txt"); }; } void draw() { if(t>next_mode*1.05) { mode=(mode+1)%2; t=0.0; if(mode==SACCADE) { last_x=x; last_y=y; r=random(30/z, 80/z)/DIV; last_z=z; z=constrain(last_z*random(0.9, 1.1), 0.25, 1.1); theta=(TWO_PI+HALF_PI*random(-0.95, 0.95))%TWO_PI; next_x=last_x+cos(theta)*r; next_y=last_y+sin(theta)*r; next_y=constrain(next_y, 0, b.height-(win_height/z)); // end condition if(next_x>b.width-win_width/z) { next_x%=(b.width-(win_width/z)); if(writeToFile) { output.flush(); // Writes the remaining data to the file output.close(); // Finishes the file }; //exit(); }; next_mode=saccade_length; } else { // RECOVER last_x=x; last_y=y; last_z=z; r=sqrt((x-last_x)*(x-last_x)+(y-last_y)*(y-last_y)); next_mode=rest_length; }; }; t+=d_t; curr_r=lerp(0, r, 1.0-(t/next_mode)); curr_z=lerp(last_z, z, (t/next_mode)); x=lerp(last_x, next_x, (t/next_mode)); y=lerp(last_y, next_y, (t/next_mode)); c = b.get(round(x), round(y), round(win_width/curr_z), round(win_height/curr_z)); hist_eq(c); blend(c, 0, 0, win_width, win_height, 0, 0, width, height, BLEND); if(toggleShow) draw_indicators(width/2+(next_x-x)*DIV/curr_z, height/2+(next_y-y)*DIV/curr_z, z); // fix draw indicators! // draw_indicators(width/2+(next_x-x)*curr_z, height/2+(next_y-y)*curr_z, z); if(writeToFile) { saveFrame(outpath+"03_washington dc bedroom 2-#####.tif"); output.println(frameCount+" "+millis()); }; } void draw_indicators(float x, float y, float z) { stroke(128); line(x-20, y, x+20, y); line(x, y-20, x, y+20); line(width/2, height/2, x, y); stroke(64); rect(width/2, height/2, width*0.8, height*0.8); stroke(0, 0, 64); rect(width/2, height/2, width*0.8*(curr_z/z), height*0.8*(curr_z/z)); }; void hist_eq(PImage in) { // equalize histogram to maximize contrast in.loadPixels(); int dimension = (in.width*in.height); // calc histo for central portion of image int [] hist = new int[256]; int top=round(float(in.height)*0.1); int bottom=round(float(in.height)*0.9); int left=round(float(in.width)*0.1); int right=round(float(in.width)*0.9); for (int i=left; i> 16) & 0xFF; // Faster way of getting red(rgb) int g = (argb >> 8) & 0xFF; // Faster way of getting green(rgb) int b = argb & 0xFF; // Faster way of getting blue(rgb) int intensity=round((r+g+b)/3.0); hist[intensity]++; }; }; // create cumulative distribution function // record min + max int [] cdf = new int[256]; int sum=0; int min_cdf=0; int max_cdf=0; boolean found_min=false; boolean found_max=false; int little_dim = (bottom-top)*(right-left); for(int i=0;i<256;i++) { sum+=hist[i]; cdf[i]=sum; if((found_min==false) && (sum>0)) { min_cdf=i; found_min=true; }; if((found_max==false) && (sum>=little_dim)) { max_cdf=i; found_max=true; }; }; // loop over pixels and replace with equalized vals for(int i=0;i> 24) & 0xFF; int r = (argb >> 16) & 0xFF; // Faster way of getting red(rgb) int g = (argb >> 8) & 0xFF; // Faster way of getting green(rgb) int b = argb & 0xFF; // Faster way of getting blue(rgb) // intensity normalization equation from // http://en.wikipedia.org/wiki/Histogram_equalization a = (a >> 1) << 24; //round(a * 0.9) << 24; r = constrain(int(norm(r, min_cdf, max_cdf)*255), 0, 255) << 16; g = constrain(int(norm(g, min_cdf, max_cdf)*255), 0, 255) << 8; b = constrain(int(norm(b, min_cdf, max_cdf)*255), 0, 255); color new_rgb = a | r | g | b; in.pixels[i]= new_rgb; }; in.updatePixels(); }; void keyPressed() { if ((key=='s') ||( key=='S')) { toggleShow = (toggleShow == true) ? false : true; }; };