Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| isp:sample_awb_implementation_in_c [2018/06/14 22:26] – [AWB::_isRedOE()] Igor Yefmov | isp:sample_awb_implementation_in_c [2022/04/04 23:32] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| * '' | * '' | ||
| - | The code below conforms to C++14 standard | + | The code below conforms to C++17 standard |
| ====== Helper one-liners ====== | ====== Helper one-liners ====== | ||
| A few short functions for code readability, | A few short functions for code readability, | ||
| + | |||
| + | Side note: I'm fully aware of the '' | ||
| <code c++> | <code c++> | ||
| Line 121: | Line 123: | ||
| ===== Constructor AWB::AWB ===== | ===== Constructor AWB::AWB ===== | ||
| - | A bulk of (quite simplistic) calculations is performed with data in '' | + | A bulk of (quite simplistic) calculations is performed with data in '' |
| <code c++> | <code c++> | ||
| Line 171: | Line 173: | ||
| // A more generic definition of this special condition is: too much red overexposure relative to | // A more generic definition of this special condition is: too much red overexposure relative to | ||
| // green overexposure relative to overall brightness of the picture. The brighter the image the | // green overexposure relative to overall brightness of the picture. The brighter the image the | ||
| - | // more overexposure we can tolerate | + | // more overexposure we can tolerate, but to a certain point |
| bool AWB:: | bool AWB:: | ||
| { | { | ||
| Line 181: | Line 183: | ||
| }else if(m_vars.avgY < 60){ | }else if(m_vars.avgY < 60){ | ||
| return m_vars.oeR > m_vars.oeG * m_vars.avgY * 3; | return m_vars.oeR > m_vars.oeG * m_vars.avgY * 3; | ||
| + | }else if(m_vars.avgY < 85){ | ||
| + | return m_vars.oeR > m_vars.oeG * m_vars.avgY; | ||
| }else{ | }else{ | ||
| - | return m_vars.oeR > m_vars.oeG * m_vars.avgY * 7; | + | return m_vars.oeR > m_vars.oeG * 8; |
| } | } | ||
| }</ | }</ | ||
| Line 190: | Line 194: | ||
| If the red channel is way hot what we do is bring it almost half-way back to where the green gain is ('' | If the red channel is way hot what we do is bring it almost half-way back to where the green gain is ('' | ||
| - | <code c++> | + | <code c++>void AWB:: |
| { | { | ||
| - | const int gainG = m_ov[Val::GAIN_G]; | + | const int gainG = m_ov[Val::gain_g]; |
| - | const int gainR = m_ov[Val::GAIN_R]; | + | const int gainR = m_ov[Val::gain_r]; |
| if(gainR > gainG){ | if(gainR > gainG){ | ||
| const auto diff = (gainG - gainR) * 5 / 8; // 62.5% closer to green gain value | const auto diff = (gainG - gainR) * 5 / 8; // 62.5% closer to green gain value | ||
| - | m_ov[Val::GAIN_R] = gainR + diff; | + | m_ov[Val::gain_r] = gainR + diff; |
| } | } | ||
| }</ | }</ | ||
| Line 206: | Line 210: | ||
| The channel' | The channel' | ||
| - | <code c++> | + | <code c++>void AWB:: |
| { | { | ||
| assert(m_vars.op == Action:: | assert(m_vars.op == Action:: | ||
| - | const auto limit = m_ov.getLimit(Val:: | + | const auto limit = m_ov.getLimit(Val:: |
| - | const double precision = 0.1; | + | const double precision = 0.01; |
| if(abs(m_vars.avgU) > precision){ | if(abs(m_vars.avgU) > precision){ | ||
| Line 218: | Line 222: | ||
| // | // | ||
| const auto gb = m_vars.avgB == 0 ? 0 : m_vars.avgG / m_vars.avgB; | const auto gb = m_vars.avgB == 0 ? 0 : m_vars.avgG / m_vars.avgB; | ||
| - | const int gainB = _box(m_ov[Val:: | + | const int gainB = _box(m_ov[Val:: |
| - | m_ov[Val::GAIN_B] = gainB; | + | m_ov[Val::gain_b] = gainB; |
| } | } | ||
| if(abs(m_vars.avgV) > precision){ | if(abs(m_vars.avgV) > precision){ | ||
| const auto gr = m_vars.avgR == 0 ? 0 : m_vars.avgG / m_vars.avgR; | const auto gr = m_vars.avgR == 0 ? 0 : m_vars.avgG / m_vars.avgR; | ||
| - | const int gainR = _box(m_ov[Val:: | + | const int gainR = _box(m_ov[Val:: |
| - | m_ov[Val::GAIN_R] = gainR; | + | m_ov[Val::gain_r] = gainR; |
| } | } | ||
| } | } | ||
| Line 234: | Line 238: | ||
| In cases when our stats collection yielded too little or too much data we need to adjust the " | In cases when our stats collection yielded too little or too much data we need to adjust the " | ||
| - | <code c++> | + | <code c++>void AWB:: |
| { | { | ||
| auto diff = _adj * m_satTH; | auto diff = _adj * m_satTH; | ||
| Line 248: | Line 252: | ||
| ====== Sample usage ====== | ====== Sample usage ====== | ||
| - | This is a copy-paste of the code used in [[manual: | + | This is a copy-paste of the code used in [[manual: |
| <code c++>void ImgAnalyzerDlg:: | <code c++>void ImgAnalyzerDlg:: | ||
| Line 286: | Line 290: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ====== Initial values ====== | ||
| + | |||
| + | Following are the initial defaults for the variables that affect the process of automatic white balance adjustment: | ||
| + | ^ Name (as seen in '' | ||
| + | | '' | ||
| + | |||