PImage b, c; int x,y, y_start; float zoom; float last_z, next_z; static float MIN_ZOOM = 0.25; static float MAX_ZOOM = 1.5; static int MIN_TRANS = 80; static int MAX_TRANS = 200; int pull_length; int t; void setup() { size(screen.width, screen.height);//, 800); b = loadImage("C:\\Swap\\Photos\\01_06_western landscape.jpg"); //noLoop(); zoom=random(MIN_ZOOM, MAX_ZOOM); last_z=zoom; next_z=constrain(last_z*random(0.90, 1.10), MIN_ZOOM, MAX_ZOOM); pull_length=int(random(MIN_TRANS, MAX_TRANS)); x=0; y_start=int(random(b.height-height)); t=0; } void draw() { //image(b, x, y); c = b.get(x, y, round(width/zoom), round(height/zoom)); hist_eq(c); blend(c, 0, 0, width, height, 0, 0, width, height, BLEND); //blend(b, x, y, round(width/zoom), round(height/zoom), 0, 0, width, height, BLEND); x+=round(random(0,5)); y=y_start+round(random(0,10)); zoom=lerp(last_z, next_z, float(t+1)/float(pull_length)); t++; if(t>=pull_length) { last_z=next_z; next_z=constrain(last_z*random(0.9, 1.1), MIN_ZOOM, MAX_ZOOM); t=0; pull_length=int(random(MIN_TRANS, MAX_TRANS)); }; } 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 << 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(); };