libcamera/utils/tuning/libtuning/modules/awb/awb.py
Stefan Klug 60d60c1367 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>
2025-02-21 17:35:03 +01:00

40 lines
968 B
Python

# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright (C) 2024, Ideas On Board
import logging
from ..module import Module
from libtuning.ctt_awb import awb
import numpy as np
logger = logging.getLogger(__name__)
class AWB(Module):
type = 'awb'
hr_name = 'AWB (Base)'
out_name = 'GenericAWB'
def __init__(self, *, debug: list):
super().__init__()
self.debug = debug
def do_calculation(self, images):
logger.info('Starting AWB calculation')
imgs = [img for img in images if img.macbeth is not None]
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}