Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
isp:automatic_exposure [2018/06/04 10:13] – created Igor Yefmov | isp:automatic_exposure [2018/06/15 01:02] – Igor Yefmov | ||
---|---|---|---|
Line 5: | Line 5: | ||
====== Effects of Black Level, Gains, and " | ====== Effects of Black Level, Gains, and " | ||
- | Below are a few sections that provide a bit of information on what effect each of the 3 types of digital settings have on the output image | + | Below are a few sections that provide a bit of information on what effect each of the 3 types of digital settings have on the output image. |
===== Black Level ===== | ===== Black Level ===== | ||
- | [[https:// | + | [[https:// |
+ | |||
+ | Remember: the brighter the pixel, the **lower** its read charge. So increasing the Black Level causes more pixels to be considered " | ||
===== Gains ===== | ===== Gains ===== | ||
Line 17: | Line 19: | ||
==== Individual color channel gains ==== | ==== Individual color channel gains ==== | ||
- | There are 3 individual Gain settings for each of the 3 color channels (Red, Green, Blue) and those are applied to pixel data corresponding to that color. Naturally changing these values has a profound effect on the output color. | + | There are 3 individual Gain settings for each of the 3 color channels (Red, Green, Blue) and those are applied to pixel data corresponding to that color. Naturally changing these values has a profound effect on the output color. The offset to increasing gain is that it will increase the noise. |
==== Global Gain ==== | ==== Global Gain ==== | ||
- | Global Gain is a Gain that is applied to **every** pixel. Adjusting this setting greatly affects the brightness of the picture while only minimally affecting the color balance. | + | Global Gain is a Gain that is applied to **every** pixel. Adjusting this setting greatly affects the brightness of the picture while only minimally affecting the color balance. The offset to increasing gain is that it will increase the noise. |
===== " | ===== " | ||
- | The timing generator outputs clocks to access the rows of the imaging array, | + | The timing generator outputs clocks to access the rows of the imaging array, |
The exposure time is controlled by adjusting the time interval between pre-charging and sampling. After the data of the pixels in the row has been sampled, it is processed through analog circuitry to correct the offset and multiply the data with corresponding Gain. Following analog processing is the ADC which outputs 10, 12, or 14 bits((depends on the sensor chip's model)) of data for each pixel in the array. | The exposure time is controlled by adjusting the time interval between pre-charging and sampling. After the data of the pixels in the row has been sampled, it is processed through analog circuitry to correct the offset and multiply the data with corresponding Gain. Following analog processing is the ADC which outputs 10, 12, or 14 bits((depends on the sensor chip's model)) of data for each pixel in the array. | ||
Line 44: | Line 46: | ||
- The global brightness average (arithmetic mean) should be in a comfortable zone around 90-100 (assuming [0..255] range for brightness) | - The global brightness average (arithmetic mean) should be in a comfortable zone around 90-100 (assuming [0..255] range for brightness) | ||
- Black level should be set to correctly reflect the visual perception of the scene and the image' | - Black level should be set to correctly reflect the visual perception of the scene and the image' | ||
+ | |||
+ | ===== Exposure step-by-step algorithm ===== | ||
+ | |||
+ | The following steps describe the auto-exposure procedure in a top-down approach: | ||
+ | - [[#Collect statistics]] | ||
+ | - [[#Decide on action to take]] and based on that: | ||
+ | - No adjustment needed - loop back to step one | ||
+ | - [[#Increase the brightness]] | ||
+ | - [[#Reduce the brightness]] | ||
+ | - Loop back to step one | ||
+ | |||
+ | ==== Collect statistics ==== | ||
+ | |||
+ | Pretty straight-forward - just collect the standard histogram data for the " | ||
+ | |||
+ | For better results the collection should be limited to the central region of the image (where the face usually is) specified by a pair of values that denote the relative vertical and horizontal sizes of that window in percentage points. As an example: a window' | ||
+ | |||
+ | ==== Decide on action to take ==== | ||
+ | The decision is based on two factors: | ||
+ | - A ratio of target brightness to the actual average brightness (e.g. if the current image' | ||
+ | - How right-hand-side heavy is the histogram. To determine that number we calculate how many right-most bars of the histogram does it take to accumulate the number of pixels that our overexposure tolerance is set to. Given an image with a total of '' | ||
+ | |||
+ | Once we have the above two factors figured out the decision tree looks as follows: | ||
+ | <code cpp> | ||
+ | enum class ExpCorrAction{STAY, | ||
+ | ExpCorrAction _needExpCorrection(int _right, double _adjY){ | ||
+ | if(_right > 60 && _adjY < 0.97){ | ||
+ | return ExpCorrAction:: | ||
+ | } | ||
+ | if(_right >= 250 && _adjY <= 1){ | ||
+ | return ExpCorrAction:: | ||
+ | } | ||
+ | if(_right < 240 && _adjY > 1.2){ | ||
+ | return ExpCorrAction:: | ||
+ | } | ||
+ | return ExpCorrAction:: | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Increase the brightness ==== | ||
+ | |||
+ | - If we have not reached the limit on Exposure setting - increase it by multiplying by the target/real brightness ratio | ||
+ | - Else, if we have not hit the Global Gain limit - increase it by multiplying by the target/real brightness ratio | ||
+ | - Else (special case!) **only** if the auto-white balance is currently turned **on** and if the brightness adjustment is very high (above '' | ||
+ | - Never increase the Green Gain beyond '' | ||
+ | - Only increase the Green Gain as much as to not cause the overflow for the Gains in Red or Blue channels (take a conservative guess and then lower it by another '' | ||
+ | |||
+ | ==== Reduce the brightness ==== | ||
+ | |||
+ | This is pretty much the opposite of the [[#Increase the brightness]] described above with the actions prioritized in the opposite order: | ||
+ | - First try to decrease the Green Gain by '' | ||
+ | - If the Green Gain is at '' | ||
+ | - If the Global Gain is already at '' | ||
===== Black Level ===== | ===== Black Level ===== | ||
Line 49: | Line 104: | ||
As the sensor processes input its electrical characteristics could fluctuate (due to, for example, heating up) requiring a manual human intervention to set an appropriate Black level (or an automated "Black level Calibration" | As the sensor processes input its electrical characteristics could fluctuate (due to, for example, heating up) requiring a manual human intervention to set an appropriate Black level (or an automated "Black level Calibration" | ||
- | ===== Exposure ===== | + | In order to automate this process one could think of Black Level as the counterpart to the overexposure. The goal is to have the Black Level set at such value as to ensure that there are no more than specified overexposure pixel count that are pitch black. |
+ | ===== Sample implementation in C++ ===== | ||
+ | [[Sample AE implementation in C++]] shows one possible implementation of the approach described above. It does use (without much explanation) some of the external structures, but those should not be hard to comprehend from their usage |