User Tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
isp:automatic_white_balance [2018/06/14 14:47] – [Sample implementation in C++] Igor Yefmovisp:automatic_white_balance [2022/04/04 23:32] (current) – external edit 127.0.0.1
Line 31: Line 31:
   - Perform the [[https://en.wikipedia.org/wiki/YUV#HDTV_with_BT.709|RGB->Y'UV]] conversion   - Perform the [[https://en.wikipedia.org/wiki/YUV#HDTV_with_BT.709|RGB->Y'UV]] conversion
   - Calculate the pixel's "saturation" using the following formula:   - Calculate the pixel's "saturation" using the following formula:
-    - ''(|U((in range -127..+127))| + |V((in range -127..+127))|) / Y((in range 0..255)) < threshold / 100''((convert threshold from percent value to relative value, i.e. convert, say, ''13%'' to ''0.13''))+    - \(\frac{|U| + |V|}{Y} < threshold, U \in [-127..+127], \in [-127..+127], \in [0..255], threshold \in [0..1]\)
       - Of course one should be careful about dividing by ''0'' so first check if the ''Y'' is not ''0'' ;-)       - Of course one should be careful about dividing by ''0'' so first check if the ''Y'' is not ''0'' ;-)
   - If the ''Y'' value is **not** ''0'' **and** ''threshold'' comparison yielded ''true'' - add that pixel's ''U'' and ''V'' components to our running totals and increment the total number of "good" pixels by ''1''   - If the ''Y'' value is **not** ''0'' **and** ''threshold'' comparison yielded ''true'' - add that pixel's ''U'' and ''V'' components to our running totals and increment the total number of "good" pixels by ''1''
Line 44: Line 44:
 ==== Calculate color properties ==== ==== Calculate color properties ====
  
-Now that we have our data set we can figure out what our picture looks like from the color balance point of view. For that we just calculate the average values of ''U'' and ''V''. The simplest approach is to calculate the [[https://en.wikipedia.org/wiki/Mean#Arithmetic_mean_(AM)|arithmetic mean]] value, but other formulae may provide more accurate results.+Now that we have our data set we can figure out what our picture looks like from the color balance point of view. For that we just calculate the average values of \(U\) and \(V\). The simplest approach is to calculate the [[https://en.wikipedia.org/wiki/Mean#Arithmetic_mean_(AM)|arithmetic mean]] value, but other formulae may provide more accurate results.
  
 At the end of this step we have the following 3 sets of numbers: At the end of this step we have the following 3 sets of numbers:
-  - "Main results" are the averages of ''U'' and ''V'' - these tell us how far off the picture is from being considered to be the "grey world" +  - "Main results" are the averages of \(U\) and \(V\) - these tell us how far off the picture is from being considered to be the "grey world" 
-  - Calculate the "average" ''R''''G'', and ''B'' values from ''U'' and ''V''+  - Calculate the "average" \(R\)\(G\), and \(B\) values from \(U\) and \(V\)
-    - Use the ''Y'' from [[#Collect statistical data set|previous step]] (if it was collected) or just go with the value of ''100'' which is hopefully a good representation of a well-adjusted overall brightness +    - Use the \(Y\) from [[#Collect statistical data set|previous step]] (if it was collected) or just go with the value of \(100\) which is hopefully a good representation of a well-adjusted overall brightness 
-  - Calculate the two ratios that represent how far off the ''Red'' and ''Blue'' colors are from the ''Green''((we use a fixed value of ''Green'' and never adjust it for color normalization)). Those ratios are ''R/G'' and ''B/G''+  - Calculate the two ratios that represent how far off the ''Red'' and ''Blue'' colors are from the ''Green''((we use a fixed value of ''Green'' and never adjust it for color normalization)). Those ratios are \(^R/_G\) and \(^B/_G\)
  
 ==== Figure out the adjustment ==== ==== Figure out the adjustment ====
Line 56: Line 56:
 Now that we have all the information we need to make a decision let's make one! Now that we have all the information we need to make a decision let's make one!
  
-  - If the **absolute** value of average ''U'' is above some arbitrary threshold (we use ''0.1'') then we need to adjust the ''Blue'' channel. In our case we just change the sensor's blue channel gain by multiplying it by the ''B/G'' ratio+  - If the **absolute** value of average \(U\) is above some arbitrary threshold (we use \(0.1\)) then we need to adjust the ''Blue'' channel. In our case we just change the sensor's blue channel gain by multiplying it by the \(^B/_G\) ratio
     - Be careful not to overflow beyond the sensor gain's cap     - Be careful not to overflow beyond the sensor gain's cap
     - If the gain is already at 0 and needs to be increased - make sure you use addition, as multiplication won't help you((or just make sure you never adjust the color channel's gain below, say, ''10'')) ;-)     - If the gain is already at 0 and needs to be increased - make sure you use addition, as multiplication won't help you((or just make sure you never adjust the color channel's gain below, say, ''10'')) ;-)
-  - Same for the ''Red'' channel, only we use the ''V'' and ''R/G'' values+  - Same for the ''Red'' channel, only we use the \(V\) and \(^R/_G\) values
  
-The ''Blue'' channel gets a bit over-saturated on the sensor we use so a tiny adjustment is introduced: the ''B/G'' ratio is offset by ''2%'' right before it is applied to the new gain's value.+The ''Blue'' channel gets a bit over-saturated on the sensor we use so a tiny adjustment is introduced: the \(^B/_G\) ratio is offset by \(2%%\) right before it is applied to the new gain's value.
  
 ===== Sample implementation in C++ ===== ===== Sample implementation in C++ =====
  
 [[Sample AWB 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 deduce from their usage [[Sample AWB 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 deduce from their usage

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information