diff options
author | Stefan Klug <stefan.klug@ideasonboard.com> | 2025-01-23 12:40:58 +0100 |
---|---|---|
committer | Stefan Klug <stefan.klug@ideasonboard.com> | 2025-02-21 17:35:03 +0100 |
commit | 60d60c13672b81f2a57894467a569c6ba98ae895 (patch) | |
tree | d6bef13c43933c7ea534ac42d2fd50888b578477 /utils/tuning/libtuning/modules | |
parent | deb3f05137ff759b937f1dcfd32b81945a01d0aa (diff) |
libtuning: module: awb: Add bayes AWB support
To support the bayesian AWB algorithm in libtuning, the necessary data
needs to be collected and written to the tuning file.
Extend libtuning to calculate and output that additional data.
Prior probabilities and AwbModes are manually specified and not
calculated in the tuning process. Add sample values from the RaspberryPi
tuning files to the example config file.
Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'utils/tuning/libtuning/modules')
-rw-r--r-- | utils/tuning/libtuning/modules/awb/awb.py | 16 | ||||
-rw-r--r-- | utils/tuning/libtuning/modules/awb/rkisp1.py | 21 |
2 files changed, 25 insertions, 12 deletions
diff --git a/utils/tuning/libtuning/modules/awb/awb.py b/utils/tuning/libtuning/modules/awb/awb.py index c154cf3b..0dc4f59d 100644 --- a/utils/tuning/libtuning/modules/awb/awb.py +++ b/utils/tuning/libtuning/modules/awb/awb.py @@ -27,10 +27,14 @@ class AWB(Module): imgs = [img for img in images if img.macbeth is not None] - gains, _, _ = awb(imgs, None, None, False) - gains = np.reshape(gains, (-1, 3)) + ct_curve, transverse_pos, transverse_neg = awb(imgs, None, None, False) + ct_curve = np.reshape(ct_curve, (-1, 3)) + gains = [{ + 'ct': int(v[0]), + 'gains': [float(1.0 / v[1]), float(1.0 / v[2])] + } for v in ct_curve] + + return {'colourGains': gains, + 'transversePos': transverse_pos, + 'transverseNeg': transverse_neg} - return [{ - 'ct': int(v[0]), - 'gains': [float(1.0 / v[1]), float(1.0 / v[2])] - } for v in gains] diff --git a/utils/tuning/libtuning/modules/awb/rkisp1.py b/utils/tuning/libtuning/modules/awb/rkisp1.py index 0c95843b..d562d26e 100644 --- a/utils/tuning/libtuning/modules/awb/rkisp1.py +++ b/utils/tuning/libtuning/modules/awb/rkisp1.py @@ -6,9 +6,6 @@ from .awb import AWB -import libtuning as lt - - class AWBRkISP1(AWB): hr_name = 'AWB (RkISP1)' out_name = 'Awb' @@ -20,8 +17,20 @@ class AWBRkISP1(AWB): return True def process(self, config: dict, images: list, outputs: dict) -> dict: - output = {} - - output['colourGains'] = self.do_calculation(images) + if not 'awb' in config['general']: + raise ValueError('AWB configuration missing') + awb_config = config['general']['awb'] + algorithm = awb_config['algorithm'] + + output = {'algorithm': algorithm} + data = self.do_calculation(images) + if algorithm == 'grey': + output['colourGains'] = data['colourGains'] + elif algorithm == 'bayes': + output['AwbMode'] = awb_config['AwbMode'] + output['priors'] = awb_config['priors'] + output.update(data) + else: + raise ValueError(f"Unknown AWB algorithm {output['algorithm']}") return output |