PImage b, c; float x,y; // variables for position float last_x, last_y; float r, theta, curr_r; // variables for sacaddic motion float target_zoom, last_zoom, curr_zoom; float t; static float d_t=0.1; static float saccade_length = 12.0; int win_width; int win_height; // variables for auto-constrast int i_min, i_max; static float discard = 0.0001; PFont fontA; // Set to 4 for 1/4 size Preview static int DIV = 3; // variables for logging of timing String outpath="output\\s_ff_blur_02\\"; PrintWriter output; static boolean writeToFile=false; void setup() { size(screen.width/DIV, screen.height/DIV);//, 800); background(0); b=loadImage("C:\\Swap\\Photos\\03_washington dc bedroom 2.jpg"); win_height=int(b.height*0.4/DIV); win_width=int(b.width*0.4/DIV); x=b.width/2; y=int(random(b.height-win_height)/2+b.height/2); last_x=x; last_y=y; last_zoom=4.0; target_zoom=1.0; frameRate(24); // for frameRate display fontA = loadFont("CourierNew36.vlw"); textFont(fontA, 32); if(writeToFile) { // setup up timing log file output = createWriter(outpath+"timing.txt"); }; } void hist_eq(PImage in) { // equalize histogram to maximize contrast in.loadPixels(); int dimension = (in.width*in.height); // create histogram int [] hist = new int[256]; for(int i=0;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; 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>=dimension)) { 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; 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 draw() { if(t > saccade_length) { last_zoom=target_zoom; target_zoom=random(0.5, 6.0); last_x=x; last_y=y; r=win_width/target_zoom+random(0, win_width/target_zoom); theta=(TWO_PI+HALF_PI*random(-0.95, 0.95))%TWO_PI; t=0.0; }; // update motion t=t+d_t; curr_r=lerp(0, r, (t/saccade_length)); curr_zoom=1.0;//lerp(last_zoom, target_zoom, (t/saccade_length)); x=last_x+(cos(theta)*curr_r); y=last_y+(sin(theta)*curr_r); //println("t: "+t+" r: "+curr_r+" z: "+curr_zoom); y=constrain(y, 0, b.height-win_height); // end condition if(x+win_width>b.width) { if(writeToFile) { output.flush(); // Writes the remaining data to the file output.close(); // Finishes the file }; exit(); }; c = b.get(round(x), round(y), round(win_width*curr_zoom), round(win_height*curr_zoom)); hist_eq(c); blend(c, 0, 0, win_width, win_height, 0, 0, width, height, BLEND); if(writeToFile) { saveFrame(outpath+"03_washington dc bedroom 2-#####.tif"); output.println(frameCount+" "+millis()); }; }