<< return to Pixycam.com

Autoexposure algorithm?

For my application I need to control the exposure, and the Pixy is complicated in having two settings, gain and compensation. Somehow the Pixy manages to make a pretty good choice quickly for those two interacting parameters. Is any information available on how that is done and when it actually happens? Upon a casual look-through nothing jumped out of the camera source code, so I assume this happens in the hardware.

I’ve done some tests to optimize the exposure histogram, by collecting fixed frames for a large selection of gain and compensation values. I calculated the mean, variance, minimum and maximum pixel value for a typical low light application setting, and it is clear from these data that the interaction between these two parameters is nonlinear and not easily modeled. It is also clear that a gain/compensation setting similar to that chosen by the camera maximizes the variance and gives a reasonable value for the average intensity, but making that choice by systematic search would be very time consuming.

The parameter choice does not appear to be critical, so ballpark values would probably be OK. Any hints on a fast algorithm for searching this nonlinear parameter space (or an explanation for how the camera does it) would be most welcome.

I’ve attached a spreadsheet from the latest experiment, a series of 2385 1280x50 frames. In successive columns are compensation, gain, pixel intensity mean, variance, min and max for the raw Bayer (uninterpolated) images. I’ve also attached a couple of surface plots showing how the frame variance (width of histogram) depends on compensation and gain. Note that the gain variable has a highly nonlinear effect, with peaks and valleys. The spreadsheet and plot labeled “variance.png” are from a low light exposure, while the second plot entitled “overcast.png” is a more normal lighting situation, with the overcast sky as a light source.

Sorry for the duplication of attachments. There seems to be no way to delete an attachment with the forum software.

Comments welcome!

I’ve attached a typical 1280x50 image, showing part of my office under low room lighting. The exposure parameters were chosen by the camera and have values compensation 821 (0x335) and gain 245 (0xf5).

BTW a great overview of digital camera autoexposure algorithms can be found at http://www.dmi.unict.it/~battiato/download/Exposure2008.pdf but the quick algorithms for estimating the proper exposure are for F stops and shutter speeds as parameters.

Cheers, Jim

It is pretty clear from the results that were posted earlier that the “gain” parameter has different bits doing different things, with the two high bits being key. The evidence for that are the deep valleys in the variance surface plot at gain = 64 and gain = 128 (bits 6 & 7).

I’ve decided to use the camera hardware to estimate the exposure parameters, save those values and then set them manually for subsequent frames.

It also appears that the camera makes some test before adjusting the compensation and gain values (when the cam_getFrame command is issued) and changes those parameters only if there is has been a significant change in the lighting. When adjusting the exposure, it seems useful to take two frames and compare the two sets of exposure parameters before moving on.

Cheers, Jim

Hi Jim,

I was looking through your posts and I am interested to find out the method you used. Based on your description you control compensation and gain. I am trying to reproduce similar tests as my application also requires changes in exposure. I would like to know, when you say you change gain and compensation, how do you do that? Is that through Pixymon and then send the commands in the list below

I understand you need to first disable AEC, set ECV and brightness according to your choices. Did you figure out what bits mean what in ECV and brightness?

Please let me know as it would be really helpful.

Thanks,

CarlosA

Hi, Carlos:

For some reason, when I log in under my original user name, I can no longer reply to any posts.

I do not know what all the bits in ECV do, as the upper (two, I think) bits do not have the same effect as the lower ones.
However it generally works to have the camera chose the proper compensation and exposure, which you can read and then set for later exposures.

You can use PixyMon or program directly. Take a look at the last code I posted in the following series for how to read the ECV and exposure values programmatically. Similar function calls can be used to set them. http://cmucam.org/boards/9/topics/5106?r=6183#message-6183