Skip to content

Commit ea8fd63

Browse files
naushirkbingham
authored andcommitted
ipa: rpi: awb: Add a bias to the AWB search
In the case of an AWB search failure, the current algorithm logic will return a point on the CT curve closest to where the search finisned. This can be quite undesirable. Instead, add some bias params to the AWB algorithm which will direct the search to a set CT value in the case where statistics become unreliable causing the search to fail. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
1 parent 692d0d6 commit ea8fd63

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/ipa/rpi/controller/rpi/awb.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ int AwbConfig::read(const libcamera::YamlObject &params)
170170
whitepointB = params["whitepoint_b"].get<double>(0.0);
171171
if (bayes == false)
172172
sensitivityR = sensitivityB = 1.0; /* nor do sensitivities make any sense */
173+
/*
174+
* The biasProportion parameter adds a small proportion of the counted
175+
* pixles to a region biased to the biasCT colour temperature.
176+
*
177+
* A typical value for biasProportion would be between 0.05 to 0.1.
178+
*/
179+
biasProportion = params["bias_proportion"].get<double>(0.0);
180+
biasCT = params["bias_ct"].get<double>(kDefaultCT);
173181
return 0;
174182
}
175183

@@ -410,7 +418,8 @@ void Awb::asyncFunc()
410418

411419
static void generateStats(std::vector<Awb::RGB> &zones,
412420
StatisticsPtr &stats, double minPixels,
413-
double minG, Metadata &globalMetadata)
421+
double minG, Metadata &globalMetadata,
422+
double biasProportion, double biasCtR, double biasCtB)
414423
{
415424
std::scoped_lock<RPiController::Metadata> l(globalMetadata);
416425

@@ -423,6 +432,14 @@ static void generateStats(std::vector<Awb::RGB> &zones,
423432
continue;
424433
zone.R = region.val.rSum / region.counted;
425434
zone.B = region.val.bSum / region.counted;
435+
/*
436+
* Add some bias samples to allow the search to tend to a
437+
* bias CT in failure cases.
438+
*/
439+
const unsigned int proportion = biasProportion * region.counted;
440+
zone.R += proportion * biasCtR;
441+
zone.B += proportion * biasCtB;
442+
zone.G += proportion * 1.0;
426443
/* Factor in the ALSC applied colour shading correction if required. */
427444
const AlscStatus *alscStatus = globalMetadata.getLocked<AlscStatus>("alsc.status");
428445
if (stats->colourStatsPos == Statistics::ColourStatsPos::PreLsc && alscStatus) {
@@ -443,7 +460,9 @@ void Awb::prepareStats()
443460
* any LSC compensation. We also ignore config_.fast in this version.
444461
*/
445462
generateStats(zones_, statistics_, config_.minPixels,
446-
config_.minG, getGlobalMetadata());
463+
config_.minG, getGlobalMetadata(),
464+
config_.biasProportion, config_.ctR.eval(config_.biasCT),
465+
config_.ctB.eval(config_.biasCT));
447466
/*
448467
* apply sensitivities, so values appear to come from our "canonical"
449468
* sensor.

src/ipa/rpi/controller/rpi/awb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ struct AwbConfig {
8787
double whitepointR;
8888
double whitepointB;
8989
bool bayes; /* use Bayesian algorithm */
90+
/* proportion of counted samples to add for the search bias */
91+
double biasProportion;
92+
/* CT target for the search bias */
93+
double biasCT;
9094
};
9195

9296
class Awb : public AwbAlgorithm

0 commit comments

Comments
 (0)