PImage img; int imgwidth = 720; int imgheight = 480; int imgcount = 0; int imgAvailable = 40; /* int imgwidth = 3; int imgheight = 3; int imgcount = 3; */ //boolean useline[][] = new boolean[imgcount][imgheight]; boolean firstpassokline[][] = new boolean[imgAvailable][imgheight]; boolean secondpassokline[][] = new boolean[imgAvailable][imgheight]; int rgbsumlevel = 300; int hitcountlevel = 1; color buf[][] = new color[imgAvailable][imgwidth*imgheight]; void draw(){ } int imagesusedinsum[] = new int[imgheight]; void setup(){ size(imgwidth,imgheight); // for(int i = 0; i < imgcount ; i++){ // workImage(i); // } } void keyReleased(){ if(key == ' '){ if(workImage(imgcount)){ imgcount++; } else { println("NO MORE"); } } if(key == 's'){ save("results.tga"); println("DONE SAVING"); } } boolean workImage(int i){ img = loadImage(i+".jpg"); if(img == null) return false; image(img,0,0); loadPixels(); for(int w = 0; w < imgwidth * imgheight; w++){ buf[i][w] = pixels[w]; } for(int y = 0; y < imgheight; y++){ firstpassokline[i][y] = usableLine(y); } println(i); for(int y = 0; y < imgheight; y++){ secondpassokline[i][y] = true; } for(int y = 0; y < imgheight; y++){ if(!firstpassokline[i][y]){ if(y >= 3) secondpassokline[i][y-3] = false; if(y >= 2) secondpassokline[i][y-2] = false; if(y >= 1) secondpassokline[i][y-1] = false; secondpassokline[i][y] = false; if(y < imgheight - 1) secondpassokline[i][y+1] = false; if(y < imgheight - 2) secondpassokline[i][y+2] = false; if(y < imgheight - 3) secondpassokline[i][y+3] = false; } } for(int y = 0; y < imgheight; y++){ if( secondpassokline[i][y]){ imagesusedinsum[y]++; } else { line(0,y,imgwidth,y); } } return true; } void mouseReleased(){ loadPixels(); int red[] = new int[imgwidth*imgheight]; int green[] = new int[imgwidth*imgheight]; int blue[] = new int[imgwidth*imgheight]; for(int whatline = 0; whatline < imgheight; whatline++){ for(int whatpos = 0 ; whatpos < imgwidth; whatpos++){ int px = (whatline * imgwidth) + whatpos; /* HashMap redpop = new HashMap(); HashMap greenpop = new HashMap(); HashMap bluepop = new HashMap();*/ for(int i = 0; i < imgcount; i++){ boolean foundSomething = false; if(secondpassokline[i][whatline]){ color p = buf[i][px]; /* incMap(redpop, (p & 0x00FC0000)>>16); incMap(greenpop,(p & 0x0000FC00)>>8); incMap(bluepop, (p & 0x000000FC)); */ red[px] += (p & 0x00FF0000)>>16; green[px] += (p & 0x0000FF00)>>8; blue[px] += (p & 0x000000FF); } } // red[px] = mostPopular(redpop); // green[px] = mostPopular(greenpop); // blue[px] = mostPopular(bluepop); } } loadPixels(); for(int whatline = 0; whatline < imgheight; whatline++){ println("in showing line "+whatline); for(int whatpos = 0 ; whatpos < imgwidth; whatpos++){ int px = (whatline * imgwidth) + whatpos; if(whatpos == 100){ println("red is "+red[px]+ "divided by"+imagesusedinsum[whatline] ); } color np; if(imagesusedinsum[whatline] == 0){ np = 0xFF000000; // println("skipping"); } else { // println(imagesusedinsum[whatline]); np = ( 0XFF000000 | ((red[px] / imagesusedinsum[whatline]) << 16) | ((green[px] / imagesusedinsum[whatline]) << 8 )| (blue[px]/ imagesusedinsum[whatline]) ); } /* color np = ( 0XFF000000 | (red[px] << 16) | (green[px] << 8) | (blue[px]) ); */ pixels[px] = np; //0XFF1200FF; //np; } } updatePixels(); println("done"); } int mostPopular(Map m){ Iterator i = m.keySet().iterator(); int mostVotes = 0; Integer winner = null; while(i.hasNext()){ Integer key = (Integer)i.next(); Integer iVotes = (Integer)m.get(key); if(iVotes.intValue() >= mostVotes){ mostVotes = iVotes.intValue(); winner = key; } } if(winner != null) { return winner.intValue(); } else { return 0; } } void incMap(Map m, int i){ Integer key = new Integer(i); Integer val = (Integer)m.get(key); if(val == null){ val = new Integer(1); } else { val = new Integer(val.intValue()+1); } m.put(key,val); } boolean usableLine(int whatline){ int numabove = 0; for(int i = 0; i < imgwidth - 1; i++){ int pixsumhere = getRGBSum(pixels[i + (imgwidth * whatline)]); int pixsumnext = getRGBSum(pixels[i + 1 + (imgwidth * whatline)]); if(abs(pixsumhere - pixsumnext) > 300){ numabove++; } } if(numabove <= hitcountlevel) return true; return false; } int getRGBSum(color p){ int red = (p & 0x00FF0000)>>16; int green = (p & 0x0000FF00)>>8; int blue = (p & 0x000000FF); return red+green+blue; }