[{"id":30121,"web_url":"https://patchwork.libcamera.org/comment/30121/","msgid":"<171957186441.392292.2603799698760692652@ping.linuxembedded.co.uk>","date":"2024-06-28T10:51:04","subject":"Re: [PATCH v2 01/25] libtuning: Backport improvements in MacBeth\n\tsearch reliability","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2024-06-28 11:46:54)\n> Port 66479605baca4a22e2b7a17c2a8cf9f9be9a7724 into libtuning.\n> Original message:\n> Improve the Macbeth Chart search reliability\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\n\nReviewed-by: Kieran Bingham <kieran.bingham@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:\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 39DDEBDB1D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 28 Jun 2024 10:51:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CEBBF62C95;\n\tFri, 28 Jun 2024 12:51:08 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4725562C95\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 28 Jun 2024 12:51:07 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id BED7D735;\n\tFri, 28 Jun 2024 12:50:42 +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=\"R4lUUxoK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1719571842;\n\tbh=sj/Hyq2tHZMg48gmu0NB2YhL5nkUWxbtrknCTvCR4iw=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=R4lUUxoKa6d7OfhTWEhB/BVcgizuRDg8a5G+8HIe5EoEh+f03ZsAkiNTbOxfgjuPh\n\tz/RYwxKD/JKFL7WEgf5O7Rys3hfByG0a9CymG8RFNdB8pP8mponEEpD4t1aoczpTCg\n\t/3FzN6a9r4IyPFsNwZHYwqgscS3NvKJRM+mHG7xA=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240628104828.2928109-2-stefan.klug@ideasonboard.com>","References":"<20240628104828.2928109-1-stefan.klug@ideasonboard.com>\n\t<20240628104828.2928109-2-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 01/25] libtuning: Backport improvements in MacBeth\n\tsearch reliability","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 28 Jun 2024 11:51:04 +0100","Message-ID":"<171957186441.392292.2603799698760692652@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}}]