We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Brightness Threshold Question (Read 689 times)
Brightness Threshold Question
May 17th, 2010, 12:35pm
 
Hi,

I'm messing around with the brightness threshold code as part of a college project but there's one thing I'd like to change but cant figure out what to do. Basically the pixels turn white if the light is above a certain threshold but what I want to do is make the pixels completely invisible. Changing the opacity of the pixels where I declare the color does the the trick (the white pixels become invisible) but unfortunately what I want to do is make the pixels of the actual video feed itself invisible so you can see through the video (as I intend to put another video feed behind it). Does anyone know how I could do this?

Code:
import processing.video.*;

color black = color(0);
color white = color(255);
int numPixels;
Capture video;

void setup() {
 size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
 strokeWeight(5);
 // Uses the default video input, see the reference if this causes an error
 video = new Capture(this, width, height, 24);
 numPixels = video.width * video.height;
 noCursor();
 smooth();
}

void draw() {
 if (video.available()) {
   video.read();
   video.loadPixels();
   int threshold = 127; // Set the threshold value
   float pixelBrightness; // Declare variable to store a pixel's color
   // Turn each pixel in the video frame black or white depending on its brightness
   loadPixels();
   for (int i = 0; i < numPixels; i++) {
     pixelBrightness = brightness(video.pixels[i]);
     if (pixelBrightness > threshold) { // If the pixel is brighter than the
       pixels[i] = white; // threshold value, make it white
     }
     else { // Otherwise,
       pixels[i] = black; // make it black
     }
   }
   updatePixels();
   // Test a location to see where it is contained. Fetch the pixel at the test
   // location (the cursor), and compute its brightness
   int testValue = get(mouseX, mouseY);
   float testBrightness = brightness(testValue);
   if (testBrightness > threshold) { // If the test location is brighter than
     fill(black); // the threshold set the fill to black
   }
   else { // Otherwise,
     fill(white); // set the fill to white
   }

 }
}
Page Index Toggle Pages: 1