Patch Detail
Show a patch.
GET /api/patches/20220/?format=api
{ "id": 20220, "url": "https://patchwork.libcamera.org/api/patches/20220/?format=api", "web_url": "https://patchwork.libcamera.org/patch/20220/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20240606101512.375178-7-david.plowman@raspberrypi.com>", "date": "2024-06-06T10:15:12", "name": "[6/6] utils: raspberrypi: ctt: Add a maximum gain parameter for LSC", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "a2b16128b458fab7ee491892232f1c90b4eace78", "submitter": { "id": 42, "url": "https://patchwork.libcamera.org/api/people/42/?format=api", "name": "David Plowman", "email": "david.plowman@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/20220/mbox/", "series": [ { "id": 4367, "url": "https://patchwork.libcamera.org/api/series/4367/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4367", "date": "2024-06-06T10:15:06", "name": "Raspberry Pi Camera Tuning Tool updates", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4367/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/20220/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/20220/checks/", "tags": {}, "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 CFA86C32CF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 6 Jun 2024 10:15:43 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0DC716546D;\n\tThu, 6 Jun 2024 12:15:43 +0200 (CEST)", "from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com\n\t[IPv6:2a00:1450:4864:20::62a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 50E8E6545F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 6 Jun 2024 12:15:34 +0200 (CEST)", "by mail-ej1-x62a.google.com with SMTP id\n\ta640c23a62f3a-a692130eb19so75975366b.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 06 Jun 2024 03:15:34 -0700 (PDT)", "from pi5-davidp.pitowers.org\n\t([2001:4d4e:300:1f:c732:5d0a:406b:ae46])\n\tby smtp.gmail.com with ESMTPSA id\n\ta640c23a62f3a-a6c805c59a2sm75809866b.50.2024.06.06.03.15.33\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 06 Jun 2024 03:15:33 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"lBI5ytY+\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1717668933; x=1718273733;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=w6ymemoopcoht9JBOz3+IjqGaOLh0VUlpCxKvexIDPY=;\n\tb=lBI5ytY+ESZ+AxU7IhHXlFpcA0co1MKX2ghrRcrkWCsGoxbRgMgdi82rfy2v3LInoo\n\trLPX9MMxnDZ2MFmcDZShQX9nNvlv2w0hlgtAKDQFJTouSxYNhDkWbvvHlGnhYSbpk9rl\n\t3uJxULbDTkEKn/q27jgkXk+iwNSRjsClBmW6d3vjeXAfc1xKudyuVxZXjU0YAGsr6bdN\n\tYI0nI2/Hj3jMp6bVKSXFzmU++YEpmCWD1UELNBILzF/mRj2Ou/uxraAYoJE2pJMPtdnz\n\t9Yb+eNtdJD4OVA9GxH6t1V6AI4A9oHIEcOOOp9WKyq5oQSulyDpPuZvv7paqd3LrKR/u\n\tij5g==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1717668933; x=1718273733;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=w6ymemoopcoht9JBOz3+IjqGaOLh0VUlpCxKvexIDPY=;\n\tb=KBbYwQ3uFmcSs+agTml/SsLUi2ywleaMvXUjm6Ya5Basq5UJEPOwi1KWqZksFZOxqL\n\tHBXeIqCPOjNj+bbTznJ4qTnxYvN9lfdz61y9Zy84XIxcIflU1f0rvDeQjXozJf2qRr5N\n\tDz0fy+EtYk/FJTWwRn9q3oy1DaqCGz3LsX2bJN/womPBL6ulo1dsVxmzHavSNiW4XcJa\n\tMeIlcMXFxIJNlSiJA+2rmvE6OCL5zOKZg6vHtd8mSQG+95dqOl/OKFOysldgyflNnLcX\n\tKu1N0eQs5CIw8RTcKZie3AFqe9ogdU6ugblDgvvo4jADIFVFvHzP2npHNgVA/StIg9ti\n\tDOcg==", "X-Gm-Message-State": "AOJu0Yw0F9xb5Vg5fGNl+VbGfRYUAozG1RPeDtncdJXXAYfg2im/uD00\n\tg62lhj6UR24ubaSxBT3cQtG3d17vQ311+7LRPE5vVBVo4W5SArsKvIPK4Vv17PsxCQIyhOEdb0R\n\tk", "X-Google-Smtp-Source": "AGHT+IEhkM/8rDYR5nhyWflyDg12IfDlp0w2oSap4FPpO3DsTPGT+cwNLHw6ZfgEZc3C3gAQl8Q6Kw==", "X-Received": "by 2002:a17:907:9516:b0:a64:a091:91f2 with SMTP id\n\ta640c23a62f3a-a699fcdf2dfmr241608166b.37.1717668933578; \n\tThu, 06 Jun 2024 03:15:33 -0700 (PDT)", "From": "David Plowman <david.plowman@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "David Plowman <david.plowman@raspberrypi.com>", "Subject": "[PATCH 6/6] utils: raspberrypi: ctt: Add a maximum gain parameter\n\tfor LSC", "Date": "Thu, 6 Jun 2024 11:15:12 +0100", "Message-Id": "<20240606101512.375178-7-david.plowman@raspberrypi.com>", "X-Mailer": "git-send-email 2.39.2", "In-Reply-To": "<20240606101512.375178-1-david.plowman@raspberrypi.com>", "References": "<20240606101512.375178-1-david.plowman@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "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>" }, "content": "A max_gain parameter is added to the config file which we pass to the\nlens shading calibration. This clamps the maximum luminance gain that\ngets written into the tuning files so as to prevent overflows.\n\nIt is particularly useful for lenses that cut off the light completely\nfrom the sensor corners, and allows usable tables to be generated for\nthem.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n utils/raspberrypi/ctt/ctt.py | 8 +++++---\n utils/raspberrypi/ctt/ctt_alsc.py | 12 ++++++++----\n utils/raspberrypi/ctt/ctt_config_example.json | 5 +++--\n 3 files changed, 16 insertions(+), 9 deletions(-)", "diff": "diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py\nindex 522933bd..96f1b5e6 100755\n--- a/utils/raspberrypi/ctt/ctt.py\n+++ b/utils/raspberrypi/ctt/ctt.py\n@@ -269,7 +269,7 @@ class Camera:\n colour channel seperately, and then partially corrects for vignetting.\n The extent of the correction depends on the 'luminance_strength' parameter.\n \"\"\"\n- def alsc_cal(self, luminance_strength, do_alsc_colour, grid_size):\n+ def alsc_cal(self, luminance_strength, do_alsc_colour, grid_size, max_gain=8.0):\n if 'rpi.alsc' in self.disable:\n return 1\n print('\\nStarting ALSC calibration')\n@@ -292,7 +292,7 @@ class Camera:\n call calibration function\n \"\"\"\n plot = \"rpi.alsc\" in self.plot\n- alsc_out = alsc_all(self, do_alsc_colour, plot, grid_size)\n+ alsc_out = alsc_all(self, do_alsc_colour, plot, grid_size, max_gain=max_gain)\n cal_cr_list, cal_cb_list, luminance_lut, av_corn = alsc_out\n \"\"\"\n write output to json and finish if not do_alsc_colour\n@@ -705,11 +705,13 @@ def run_ctt(json_output, directory, config, log_output, json_template, grid_size\n alsc_d = get_config(configs, \"alsc\", {}, 'dict')\n do_alsc_colour = get_config(alsc_d, \"do_alsc_colour\", 1, 'bool')\n luminance_strength = get_config(alsc_d, \"luminance_strength\", 0.8, 'num')\n+ lsc_max_gain = get_config(alsc_d, \"max_gain\", 8.0, 'num')\n blacklevel = get_config(configs, \"blacklevel\", -1, 'num')\n macbeth_d = get_config(configs, \"macbeth\", {}, 'dict')\n mac_small = get_config(macbeth_d, \"small\", 0, 'bool')\n mac_show = get_config(macbeth_d, \"show\", 0, 'bool')\n mac_config = (mac_small, mac_show)\n+ print(\"Read lsc_max_gain\", lsc_max_gain)\n \n if blacklevel < -1 or blacklevel >= 2**16:\n print('\\nInvalid blacklevel, defaulted to 64')\n@@ -750,7 +752,7 @@ def run_ctt(json_output, directory, config, log_output, json_template, grid_size\n Cam.json['rpi.black_level']['black_level'] = Cam.blacklevel_16\n Cam.json_remove(disable)\n print('\\nSTARTING CALIBRATIONS')\n- Cam.alsc_cal(luminance_strength, do_alsc_colour, grid_size)\n+ Cam.alsc_cal(luminance_strength, do_alsc_colour, grid_size, max_gain=lsc_max_gain)\n Cam.geq_cal()\n Cam.lux_cal()\n Cam.noise_cal()\ndiff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py\nindex 66ce8c14..1d94dfa5 100644\n--- a/utils/raspberrypi/ctt/ctt_alsc.py\n+++ b/utils/raspberrypi/ctt/ctt_alsc.py\n@@ -13,7 +13,7 @@ from mpl_toolkits.mplot3d import Axes3D\n \"\"\"\n preform alsc calibration on a set of images\n \"\"\"\n-def alsc_all(Cam, do_alsc_colour, plot, grid_size=(16, 12)):\n+def alsc_all(Cam, do_alsc_colour, plot, grid_size=(16, 12), max_gain=8.0):\n imgs_alsc = Cam.imgs_alsc\n grid_w, grid_h = grid_size\n \"\"\"\n@@ -24,7 +24,7 @@ def alsc_all(Cam, do_alsc_colour, plot, grid_size=(16, 12)):\n list_cb = []\n list_cg = []\n for Img in imgs_alsc:\n- col, cr, cb, cg, size = alsc(Cam, Img, do_alsc_colour, plot, grid_size=grid_size)\n+ col, cr, cb, cg, size = alsc(Cam, Img, do_alsc_colour, plot, grid_size=grid_size, max_gain=max_gain)\n list_col.append(col)\n list_cr.append(cr)\n list_cb.append(cb)\n@@ -118,7 +118,7 @@ def alsc_all(Cam, do_alsc_colour, plot, grid_size=(16, 12)):\n \"\"\"\n calculate g/r and g/b for 32x32 points arranged in a grid for a single image\n \"\"\"\n-def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12)):\n+def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12), max_gain=8.0):\n Cam.log += '\\nProcessing image: ' + Img.name\n grid_w, grid_h = grid_size\n \"\"\"\n@@ -153,9 +153,12 @@ def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12)):\n median blur to remove peaks and save as float 64\n \"\"\"\n cr = cv2.medianBlur(cr, 3).astype('float64')\n+ cr = cr/np.min(cr) # gain tables are easier for humans to read if the minimum is 1.0\n cb = cv2.medianBlur(cb, 3).astype('float64')\n+ cb = cb/np.min(cb)\n cg = cv2.medianBlur(cg, 3).astype('float64')\n cg = cg/np.min(cg)\n+ cg = [min(v, max_gain) for v in cg.flatten()] # never exceed the max luminance gain\n \n \"\"\"\n debugging code showing 2D surface plot of vignetting. Quite useful for\n@@ -179,7 +182,7 @@ def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12)):\n # print(Img.str)\n plt.show()\n \n- return Img.col, cr.flatten(), cb.flatten(), cg.flatten(), (w, h, dx, dy)\n+ return Img.col, cr.flatten(), cb.flatten(), cg, (w, h, dx, dy)\n \n else:\n \"\"\"\n@@ -189,6 +192,7 @@ def alsc(Cam, Img, do_alsc_colour, plot=False, grid_size=(16, 12)):\n cg = np.reshape(1/g, (grid_h, grid_w)).astype('float32')\n cg = cv2.medianBlur(cg, 3).astype('float64')\n cg = cg/np.min(cg)\n+ cg = [min(v, max_gain) for v in cg.flatten()] # never exceed the max luminance gain\n \n if plot:\n hf = plt.figure(figssize=(8, 8))\ndiff --git a/utils/raspberrypi/ctt/ctt_config_example.json b/utils/raspberrypi/ctt/ctt_config_example.json\nindex c7f90761..1105862c 100644\n--- a/utils/raspberrypi/ctt/ctt_config_example.json\n+++ b/utils/raspberrypi/ctt/ctt_config_example.json\n@@ -3,7 +3,8 @@\n \"plot\": [],\n \"alsc\": {\n \"do_alsc_colour\": 1,\n- \"luminance_strength\": 0.5\n+ \"luminance_strength\": 0.8,\n+ \"max_gain\": 8.0\n },\n \"awb\": {\n \"greyworld\": 0\n@@ -13,4 +14,4 @@\n \"small\": 0,\n \"show\": 0\n }\n-}\n\\ No newline at end of file\n+}\n", "prefixes": [ "6/6" ] }