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
best way to make the camera grayscale (Read 1333 times)
best way to make the camera grayscale
Oct 26th, 2005, 5:24am
 
whats the least processor intensive way of making incoming iSight video grayscale?

the filter function doesn't seem to work, and even with it I bet it would be mighty slow.

Thanks Smiley
Re: best way to make the camera grayscale
Reply #1 - Oct 26th, 2005, 12:39pm
 
You should be able to set that in your cameras settings I believe, making calculations unneccesary.

Otherwise usually something like this formula is used:
Brightness = 0.299*(r) + 0.587*(g) + 0.114*(b)

The next option would be to use a HSB colorspace (set with colorMode) to use the B value as brightness.

So there are quite some options Smiley
Re: best way to make the camera grayscale
Reply #2 - Oct 26th, 2005, 7:35pm
 
If I'm tracking brightness, wont that screw up the input?
I dont think the iSight has any built in options to make it grayscale sadly.

Re: best way to make the camera grayscale
Reply #3 - Oct 26th, 2005, 10:27pm
 
You could use:
Code:

int grey(color p) {
return max((p >> 16) & 0xff, (p >> 8) & 0xff, p & 0xff);
}

Even if you iterate throught the entire pixels array you should get through it pretty fast. If you wanted a float value you would use Brightness(), and you don't have to change the colorMode(). And no it doesn't screw the image, I spent all last year making photo filters based on automata - if the brightness command could wear out there would be a lot of blank spaces in my code by now. If you're doing a reactive work of art there's no point in changing the whole image, just read the gray value from the point in question.

Eep. My dodgy internet connection made me post twice - removed it.
Re: best way to make the camera grayscale
Reply #4 - Oct 26th, 2005, 11:47pm
 
if you're not going to display the image, but just want to work with "grayscale" to analyze it AND if you're after speed over precision it'd be enough to just use a single colour channel. in this case it'd be the green one as this carries the biggest luminance information (and as you can tell from the equation posted above).

if you're just after displaying a grayscale version of the video feed you do can use filter(GRAY) on a Capture object, only you'll have to use a slightly different syntax:

Code:
Capture myCapture;
....

void draw() {
// execute the filter for the Capture image
myCapture.filter(GRAY);
...
}

btw. the GRAY filter does proper grayscale conversion using a faster fixed precision version of the above equation.

speaking of filters: they're 2 new ones included since 0093+ which are still undocumented:

filter(ERODE) - reduces bright areas in an image
filter(DILATE) - reduces dark areas in an image

hth!
Page Index Toggle Pages: 1