[{"id":30302,"web_url":"https://patchwork.libcamera.org/comment/30302/","msgid":"<20240704091808.GC1546@pendragon.ideasonboard.com>","date":"2024-07-04T09:18:08","subject":"Re: [PATCH v3 01/23] libtuning: Backport improvements in MacBeth\n\tsearch reliability","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Jul 03, 2024 at 04:16:50PM +0200, Stefan Klug wrote:\n> Port 66479605baca4a22e2b7a17c2a8cf9f9be9a7724 into libtuning.\n> Original message:\n> Improve the Macbeth Chart search reliability\n\nPort commit 66479605baca (\"utils: raspberrypi: ctt: Improve the Macbeth\nChart search reliability\") into libtuning.\n\n> Previously the code would brighten up images in case the Macbeth Chart\n> is slightly dark, and also zoom in on sections of it to look for\n> charts occupying less of the field of view. But it would not do both\n> together.\n> \n> This change makes the search for smaller charts also repeat that\n> search for the brightened up images that it made earlier, thereby\n> increasing the chances of success for non-optimal tuning images.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  utils/tuning/libtuning/macbeth.py | 38 ++++++++++++++++++-------------\n>  1 file changed, 22 insertions(+), 16 deletions(-)\n> \n> diff --git a/utils/tuning/libtuning/macbeth.py b/utils/tuning/libtuning/macbeth.py\n> index e11824646a4f..81f3e87c9088 100644\n> --- a/utils/tuning/libtuning/macbeth.py\n> +++ b/utils/tuning/libtuning/macbeth.py\n> @@ -403,10 +403,15 @@ def find_macbeth(img, mac_config):\n>      # nothing more is tried as this is a high enough confidence to ensure\n>      # reliable macbeth square centre placement.\n>  \n> +    # Keep a list that will include this and any brightened up versions of\n> +    # the image for reuse.\n> +    all_images = [img]\n> +\n>      for brightness in [2, 4]:\n>          if cor >= 0.75:\n>              break\n>          img_br = cv2.convertScaleAbs(img, alpha=brightness, beta=0)\n> +        all_images.append(img_br)\n>          cor_b, mac_b, coords_b, ret_b = get_macbeth_chart(img_br, ref_data)\n>          if cor_b > cor:\n>              cor, mac, coords, ret = cor_b, mac_b, coords_b, ret_b\n> @@ -456,23 +461,24 @@ def find_macbeth(img, mac_config):\n>          w_inc = int(w * pair['inc'])\n>          h_inc = int(h * pair['inc'])\n>  \n> -        loop = ((1 - pair['sel']) / pair['inc']) + 1\n> +        loop = int(((1 - pair['sel']) / pair['inc']) + 1)\n>          # For each subselection, look for a macbeth chart\n> -        for i in range(loop):\n> -            for j in range(loop):\n> -                w_s, h_s = i * w_inc, j * h_inc\n> -                img_sel = img[w_s:w_s + w_sel, h_s:h_s + h_sel]\n> -                cor_ij, mac_ij, coords_ij, ret_ij = get_macbeth_chart(img_sel, ref_data)\n> -\n> -                # If the correlation is better than the best then record the\n> -                # scale and current subselection at which macbeth chart was\n> -                # found. Also record the coordinates, macbeth chart and message.\n> -                if cor_ij > cor:\n> -                    cor = cor_ij\n> -                    mac, coords, ret = mac_ij, coords_ij, ret_ij\n> -                    ii, jj = i, j\n> -                    w_best, h_best = w_inc, h_inc\n> -                    d_best = index + 1\n> +        for img_br in all_images:\n> +            for i in range(loop):\n> +                for j in range(loop):\n> +                    w_s, h_s = i * w_inc, j * h_inc\n> +                    img_sel = img_br[w_s:w_s + w_sel, h_s:h_s + h_sel]\n> +                    cor_ij, mac_ij, coords_ij, ret_ij = get_macbeth_chart(img_sel, ref_data)\n> +\n> +                    # If the correlation is better than the best then record the\n> +                    # scale and current subselection at which macbeth chart was\n> +                    # found. Also record the coordinates, macbeth chart and message.\n> +                    if cor_ij > cor:\n> +                        cor = cor_ij\n> +                        mac, coords, ret = mac_ij, coords_ij, ret_ij\n> +                        ii, jj = i, j\n> +                        w_best, h_best = w_inc, h_inc\n> +                        d_best = index + 1\n>  \n>      # Transform coordinates from subselection to original image\n>      if ii != -1:","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 A08D4BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Jul 2024 09:18:35 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EFDFA62E26;\n\tThu,  4 Jul 2024 11:18:34 +0200 (CEST)","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 25E7D62E01\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Jul 2024 11:18:34 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(117.145-247-81.adsl-dyn.isp.belgacom.be [81.247.145.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6BDA163D;\n\tThu,  4 Jul 2024 11:18:05 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"tRuNY5Dp\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1720084685;\n\tbh=Xa5ZDZiRphnrrt2j6IOr1M8k086fILFqHYyHG25QC8w=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=tRuNY5Dp9+2T3nXeDlQXGdT6waMRHTNofdkzbs+sUJagmR0HKrZs1MdJDqmQLvM+K\n\tJLvunY4uCUNBDBFPuv2sAaPQvot97XHJuwZ8J3g/4Hi/wzaBRpLlluu5vl/TcF+Tyq\n\tkRg+gw4BeQ/5V6YP1lwFNeyjog1RWPXFrPB5UxBU=","Date":"Thu, 4 Jul 2024 12:18:08 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tPaul Elder <paul.elder@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH v3 01/23] libtuning: Backport improvements in MacBeth\n\tsearch reliability","Message-ID":"<20240704091808.GC1546@pendragon.ideasonboard.com>","References":"<20240703141726.252368-1-stefan.klug@ideasonboard.com>\n\t<20240703141726.252368-2-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240703141726.252368-2-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>"}}]