Naive answer - compute average brightness of the image, take in the desired average brightness, and then adjust each pixel. For computer-vision purposes I would compute the average brightness as ab = sum ((r^2+g^2+b^2)/(255^2*3)), and I would adjust (using db = desired brightness) as: r* = r * db / ab, g* = g * db / ab, b* = b * db / ab for every (r,g,b) in the image. However, human perception differs from the way web cam works, so there might be a better formula.
– Hamish GrubijanJan 25 '10 at 02:21