Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

iphone - Determining Image Luminance/Brightness

My iphone application captures the realtime data from camera using AVFoundation's AVCaptureSession. I'm able to access that data in it's delegate method in runtime and create an image out of it. It can be CGImage, UIImage or just raw data (CMSampleBufferRef).

What I'm trying to do is to calculate luminance, brightness of that data (image). Or it can be some other value that can indicate me how bright the input light is.

Is there any standard way to get this value? Perhaps using OpenGL.

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just convert your image to YUV format and calculate the average of luma channel. Color conversion is a typical operation and any decent image processing framework supports it. For example, OpenCV (you said OpenGL, but that really doesn't have anything to do with image processing, I'm assuming you meant OpenCV) has CvtColor.

If you don't have such a framework handy but have access to the pixel intensities, you can use the equation:

Y' = 0.299*R + 0.587*G + 0.144*B

to get the luma channel, and then calculate the average. R, G and B represent the red, green and blue channels respectively.

EDIT

Note that it is possible that your camera will compensate for bright/dark scenes by modifying its aperture. This is camera-dependent, but I think most cameras do this -- otherwise your pictures can end up either saturated (pure white) or plain black -- in either case, useless. Human eyes actually do the same thing.

The downside is that's it's hard to tell whether you are in a dark or light environment just by looking at an image. In that case, you may have to go beyond the image and query the camera. In theory, you can do this either directly through a driver (unlikely) or perhaps by looking at the image metadata (e.g. with JPEG, there's EXIF).

Lastly, you haven't said what it is exactly you want to know the brightness of. If it's the overall scene, then average will be good enough. If it's some part of the scene, you may have to do something a bit smarter. Let us know if that's the case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...