[{"id":33066,"web_url":"https://patchwork.libcamera.org/comment/33066/","msgid":"<Z4WsUVEhBYmqYXOt@pyrite.rasen.tech>","date":"2025-01-14T00:14:09","subject":"Re: [PATCH v1 08/11] libtuning: module: awb: Add bayes AWB support","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Thu, Jan 09, 2025 at 12:53:59PM +0100, Stefan Klug wrote:\n> To support the bayesian AWB algorithm in libtuning, the necessary data\n> needs to be collected and written to the tuning file.\n> \n> Prior probabilities and AwbModes are defined by the user and therefore\n> added to the example config file.\n> \n> Extend the output to also contain the necessary data for the bayesian\n> AWB algorithm.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> ---\n>  utils/tuning/config-example.yaml             | 34 +++++++++++++++++++-\n>  utils/tuning/libtuning/modules/awb/awb.py    | 16 +++++----\n>  utils/tuning/libtuning/modules/awb/rkisp1.py | 21 ++++++++----\n>  3 files changed, 58 insertions(+), 13 deletions(-)\n> \n> diff --git a/utils/tuning/config-example.yaml b/utils/tuning/config-example.yaml\n> index 1b7f52cd2fff..30e88341df01 100644\n> --- a/utils/tuning/config-example.yaml\n> +++ b/utils/tuning/config-example.yaml\n> @@ -5,7 +5,39 @@ general:\n>      do_alsc_colour: 1\n>      luminance_strength: 0.5\n>    awb:\n> -    greyworld: 0\n> +    # Algorithm can be either 'grey' or 'bayes'\n> +    algorithm: bayes\n> +    # priors is only used for the bayes algorithm\n> +    priors:\n> +      - lux: 0\n> +        ct: [ 2000, 13000]\n\nI think s/]/ ]/ would be nicer.\n\n> +        probability: [ 1.0, 1.0 ]\n> +    AwbMode:\n> +      AwbAuto:\n> +        lo: 2500\n> +        hi: 8000\n> +      AwbIncandescent:\n> +        lo: 2500\n> +        hi: 3000\n> +      AwbTungsten:\n> +        lo: 3000\n> +        hi: 3500\n> +      AwbFluorescent:\n> +        lo: 4000\n> +        hi: 4700\n> +      AwbIndoor:\n> +        lo: 3000\n> +        hi: 5000\n> +      AwbDaylight:\n> +        lo: 5500\n> +        hi: 6500\n> +      AwbCloudy:\n> +        lo: 6500\n> +        hi: 8000\n> +      # One custom mode can be defined if needed\n> +      #AwbCustom:\n> +      #  lo: 2000\n> +      #  hi: 1300\n>    macbeth:\n>      small: 1\n>      show: 0\n> diff --git a/utils/tuning/libtuning/modules/awb/awb.py b/utils/tuning/libtuning/modules/awb/awb.py\n> index c154cf3b8609..0dc4f59dcb26 100644\n> --- a/utils/tuning/libtuning/modules/awb/awb.py\n> +++ b/utils/tuning/libtuning/modules/awb/awb.py\n> @@ -27,10 +27,14 @@ class AWB(Module):\n>  \n>          imgs = [img for img in images if img.macbeth is not None]\n>  \n> -        gains, _, _ = awb(imgs, None, None, False)\n> -        gains = np.reshape(gains, (-1, 3))\n> +        ct_curve, transverse_pos, transverse_neg = awb(imgs, None, None, False)\n> +        ct_curve = np.reshape(ct_curve, (-1, 3))\n> +        gains = [{\n> +            'ct': int(v[0]),\n> +            'gains': [float(1.0 / v[1]), float(1.0 / v[2])]\n> +        } for v in ct_curve]\n> +\n> +        return {'colourGains': gains,\n> +                'transversePos': transverse_pos,\n> +                'transverseNeg': transverse_neg}\n\nI don't think we use transversePos and transverseNeg?\n\n\nPaul\n\n>  \n> -        return [{\n> -                    'ct': int(v[0]),\n> -                    'gains': [float(1.0 / v[1]), float(1.0 / v[2])]\n> -                } for v in gains]\n> diff --git a/utils/tuning/libtuning/modules/awb/rkisp1.py b/utils/tuning/libtuning/modules/awb/rkisp1.py\n> index 0c95843b83d3..d562d26eb8cc 100644\n> --- a/utils/tuning/libtuning/modules/awb/rkisp1.py\n> +++ b/utils/tuning/libtuning/modules/awb/rkisp1.py\n> @@ -6,9 +6,6 @@\n>  \n>  from .awb import AWB\n>  \n> -import libtuning as lt\n> -\n> -\n>  class AWBRkISP1(AWB):\n>      hr_name = 'AWB (RkISP1)'\n>      out_name = 'Awb'\n> @@ -20,8 +17,20 @@ class AWBRkISP1(AWB):\n>          return True\n>  \n>      def process(self, config: dict, images: list, outputs: dict) -> dict:\n> -        output = {}\n> -\n> -        output['colourGains'] = self.do_calculation(images)\n> +        if not 'awb' in config['general']:\n> +            raise ValueError('AWB configuration missing')\n> +        awb_config = config['general']['awb']\n> +        algorithm = awb_config['algorithm']\n> +\n> +        output = {'algorithm': algorithm}\n> +        data = self.do_calculation(images)\n> +        if algorithm == 'grey':\n> +            output['colourGains'] = data['colourGains']\n> +        elif algorithm == 'bayes':\n> +            output['AwbMode'] = awb_config['AwbMode']\n> +            output['priors'] = awb_config['priors']\n> +            output.update(data)\n> +        else:\n> +            raise ValueError(f\"Unknown AWB algorithm {output['algorithm']}\")\n>  \n>          return output\n> -- \n> 2.43.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 4008DC326C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Jan 2025 00:14:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A434F6851C;\n\tTue, 14 Jan 2025 01:14:45 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E80A3603C1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jan 2025 01:14:44 +0100 (CET)","from pyrite.rasen.tech (unknown [173.16.167.215])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AB940465;\n\tTue, 14 Jan 2025 01:13:47 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"tXbeVy7h\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736813628;\n\tbh=YtqLAaODZmVSg9LZskKToNf5pvkfzPEGa8hilPhZKJs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=tXbeVy7hdsJ/AB+D+bx9zY9mORIRuqYAagmIT8iZtE1EFspoZDkfqnbNau1pYEgQo\n\tCmJEEQ/J8jgUQ61yXGDxoLOjJZZwJI3+n2YCfA2Uh6NTnEu/38K8JwkQMooBe3UPAX\n\t8vRCR6ruM34A+qYRS6VNuelEhGg153L8nkmmR4AA=","Date":"Mon, 13 Jan 2025 18:14:09 -0600","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1 08/11] libtuning: module: awb: Add bayes AWB support","Message-ID":"<Z4WsUVEhBYmqYXOt@pyrite.rasen.tech>","References":"<20250109115412.356768-1-stefan.klug@ideasonboard.com>\n\t<20250109115412.356768-9-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20250109115412.356768-9-stefan.klug@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":33067,"web_url":"https://patchwork.libcamera.org/comment/33067/","msgid":"<Z4WuWaPmU0eZBEfz@pyrite.rasen.tech>","date":"2025-01-14T00:22:49","subject":"Re: [PATCH v1 08/11] libtuning: module: awb: Add bayes AWB support","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Mon, Jan 13, 2025 at 06:14:09PM -0600, Paul Elder wrote:\n> On Thu, Jan 09, 2025 at 12:53:59PM +0100, Stefan Klug wrote:\n> > To support the bayesian AWB algorithm in libtuning, the necessary data\n> > needs to be collected and written to the tuning file.\n> > \n> > Prior probabilities and AwbModes are defined by the user and therefore\n> > added to the example config file.\n> > \n> > Extend the output to also contain the necessary data for the bayesian\n> > AWB algorithm.\n> > \n> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > ---\n> >  utils/tuning/config-example.yaml             | 34 +++++++++++++++++++-\n> >  utils/tuning/libtuning/modules/awb/awb.py    | 16 +++++----\n> >  utils/tuning/libtuning/modules/awb/rkisp1.py | 21 ++++++++----\n> >  3 files changed, 58 insertions(+), 13 deletions(-)\n> > \n> > diff --git a/utils/tuning/config-example.yaml b/utils/tuning/config-example.yaml\n> > index 1b7f52cd2fff..30e88341df01 100644\n> > --- a/utils/tuning/config-example.yaml\n> > +++ b/utils/tuning/config-example.yaml\n> > @@ -5,7 +5,39 @@ general:\n> >      do_alsc_colour: 1\n> >      luminance_strength: 0.5\n> >    awb:\n> > -    greyworld: 0\n> > +    # Algorithm can be either 'grey' or 'bayes'\n> > +    algorithm: bayes\n> > +    # priors is only used for the bayes algorithm\n> > +    priors:\n> > +      - lux: 0\n> > +        ct: [ 2000, 13000]\n> \n> I think s/]/ ]/ would be nicer.\n> \n> > +        probability: [ 1.0, 1.0 ]\n> > +    AwbMode:\n> > +      AwbAuto:\n> > +        lo: 2500\n> > +        hi: 8000\n> > +      AwbIncandescent:\n> > +        lo: 2500\n> > +        hi: 3000\n> > +      AwbTungsten:\n> > +        lo: 3000\n> > +        hi: 3500\n> > +      AwbFluorescent:\n> > +        lo: 4000\n> > +        hi: 4700\n> > +      AwbIndoor:\n> > +        lo: 3000\n> > +        hi: 5000\n> > +      AwbDaylight:\n> > +        lo: 5500\n> > +        hi: 6500\n> > +      AwbCloudy:\n> > +        lo: 6500\n> > +        hi: 8000\n> > +      # One custom mode can be defined if needed\n> > +      #AwbCustom:\n> > +      #  lo: 2000\n> > +      #  hi: 1300\n> >    macbeth:\n> >      small: 1\n> >      show: 0\n> > diff --git a/utils/tuning/libtuning/modules/awb/awb.py b/utils/tuning/libtuning/modules/awb/awb.py\n> > index c154cf3b8609..0dc4f59dcb26 100644\n> > --- a/utils/tuning/libtuning/modules/awb/awb.py\n> > +++ b/utils/tuning/libtuning/modules/awb/awb.py\n> > @@ -27,10 +27,14 @@ class AWB(Module):\n> >  \n> >          imgs = [img for img in images if img.macbeth is not None]\n> >  \n> > -        gains, _, _ = awb(imgs, None, None, False)\n> > -        gains = np.reshape(gains, (-1, 3))\n> > +        ct_curve, transverse_pos, transverse_neg = awb(imgs, None, None, False)\n> > +        ct_curve = np.reshape(ct_curve, (-1, 3))\n> > +        gains = [{\n> > +            'ct': int(v[0]),\n> > +            'gains': [float(1.0 / v[1]), float(1.0 / v[2])]\n> > +        } for v in ct_curve]\n> > +\n> > +        return {'colourGains': gains,\n> > +                'transversePos': transverse_pos,\n> > +                'transverseNeg': transverse_neg}\n> \n> I don't think we use transversePos and transverseNeg?\n> \n> \n> Paul\n> \n> >  \n> > -        return [{\n> > -                    'ct': int(v[0]),\n> > -                    'gains': [float(1.0 / v[1]), float(1.0 / v[2])]\n> > -                } for v in gains]\n> > diff --git a/utils/tuning/libtuning/modules/awb/rkisp1.py b/utils/tuning/libtuning/modules/awb/rkisp1.py\n> > index 0c95843b83d3..d562d26eb8cc 100644\n> > --- a/utils/tuning/libtuning/modules/awb/rkisp1.py\n> > +++ b/utils/tuning/libtuning/modules/awb/rkisp1.py\n> > @@ -6,9 +6,6 @@\n> >  \n> >  from .awb import AWB\n> >  \n> > -import libtuning as lt\n> > -\n> > -\n> >  class AWBRkISP1(AWB):\n> >      hr_name = 'AWB (RkISP1)'\n> >      out_name = 'Awb'\n> > @@ -20,8 +17,20 @@ class AWBRkISP1(AWB):\n> >          return True\n> >  \n> >      def process(self, config: dict, images: list, outputs: dict) -> dict:\n> > -        output = {}\n> > -\n> > -        output['colourGains'] = self.do_calculation(images)\n> > +        if not 'awb' in config['general']:\n> > +            raise ValueError('AWB configuration missing')\n> > +        awb_config = config['general']['awb']\n> > +        algorithm = awb_config['algorithm']\n> > +\n> > +        output = {'algorithm': algorithm}\n> > +        data = self.do_calculation(images)\n> > +        if algorithm == 'grey':\n> > +            output['colourGains'] = data['colourGains']\n> > +        elif algorithm == 'bayes':\n> > +            output['AwbMode'] = awb_config['AwbMode']\n> > +            output['priors'] = awb_config['priors']\n> > +            output.update(data)\n\nOh nvm I found it :)\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> > +        else:\n> > +            raise ValueError(f\"Unknown AWB algorithm {output['algorithm']}\")\n> >  \n> >          return output\n> > -- \n> > 2.43.0\n> >","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B17D6BD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Jan 2025 00:23:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D26846851D;\n\tTue, 14 Jan 2025 01:23:26 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C1B3684E7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jan 2025 01:23:25 +0100 (CET)","from pyrite.rasen.tech (unknown [173.16.167.215])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E6AD0465;\n\tTue, 14 Jan 2025 01:22:27 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"cpzOA+J6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736814148;\n\tbh=4yWu55oGxEQ4z0siMg5ppTRdGLzw7f6SCPUd43tmeqQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=cpzOA+J6JvfE0wdBma7RtyJmb0lRcfxqIbIVj5Wd/+YH2kdBAe3ofVivmqmfd8HMv\n\tliPp/Kv7+9/TldnIKd05PSJdj2HbuAj17A+c+aX5RcqPKZeRhBR4s6/PeSitEazaI6\n\twz2O1drxOB2SQGc12UvS5adwp7VVFFvzpj0/sj/s=","Date":"Mon, 13 Jan 2025 18:22:49 -0600","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1 08/11] libtuning: module: awb: Add bayes AWB support","Message-ID":"<Z4WuWaPmU0eZBEfz@pyrite.rasen.tech>","References":"<20250109115412.356768-1-stefan.klug@ideasonboard.com>\n\t<20250109115412.356768-9-stefan.klug@ideasonboard.com>\n\t<Z4WsUVEhBYmqYXOt@pyrite.rasen.tech>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<Z4WsUVEhBYmqYXOt@pyrite.rasen.tech>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]