User Tools

Site Tools


cs276:fix_threshold
PImage img1;
 
 void setup() {
   img1 = loadImage("fam.jpg");
   size(img1.width, img1.height);
 }
 
 void draw() {
   float y = map(mouseY, 0, height, 0, 255);
   threshold(img1, y);
   image(img1, 0, 10);
 
 }
 
void threshold(PImage img1, float y) {
  img1.loadPixels();
 
  for(int row = 0; row < img1.height; row++)
    for(int col = 0; col < img1.width; col++)
    {
      color c = img1.get(col, row);
      float r = red(c);
      float g = green(c);
      float b = blue(c);
 
      float luminance = (r + g + b) / 3.0;
 
      if (luminance < y) {
        img1.set(col, row, color(0, 0, 0));
      } else {
        img1.set(col, row, color(255, 255, 255));
      }
    }
 
  img1.updatePixels();
}
cs276/fix_threshold.txt · Last modified: 2016/02/23 11:02 by devantej2