utils: tuning: libtuning: Fix tuning for non RGGB RAWs
diff mbox series

Message ID 20241217150007.376357-1-stefan.klug@ideasonboard.com
State Accepted
Headers show
Series
  • utils: tuning: libtuning: Fix tuning for non RGGB RAWs
Related show

Commit Message

Stefan Klug Dec. 17, 2024, 2:59 p.m. UTC
Tuning fails for raw images that don't have the channels ordered in
RGGB.  In 19dc8c28f63c ("utils: tuning: libtuning: Implement the core of
libtuning") the channels of the image were reordered to RGGB
unconditionally in _read_image_dng(). That change was not applied to the
ctt_awb code, so that the channels were reordered twice. Fix by removing
the double ordering.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 utils/tuning/libtuning/ctt_awb.py | 3 +--
 utils/tuning/libtuning/image.py   | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

Comments

Isaac Scott Dec. 17, 2024, 3:34 p.m. UTC | #1
Hi Stefan,

Thanks for getting this working!

Tested on OV8858.

Tested-by: Isaac Scott <isaac.scott@ideasonboard.com>

On Tue, 2024-12-17 at 15:59 +0100, Stefan Klug wrote:
> Tuning fails for raw images that don't have the channels ordered in
> RGGB.  In 19dc8c28f63c ("utils: tuning: libtuning: Implement the core
> of
> libtuning") the channels of the image were reordered to RGGB
> unconditionally in _read_image_dng(). That change was not applied to
> the
> ctt_awb code, so that the channels were reordered twice. Fix by
> removing
> the double ordering.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> ---
>  utils/tuning/libtuning/ctt_awb.py | 3 +--
>  utils/tuning/libtuning/image.py   | 2 +-
>  2 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/utils/tuning/libtuning/ctt_awb.py
> b/utils/tuning/libtuning/ctt_awb.py
> index 117612f2582a..240f37e644bb 100644
> --- a/utils/tuning/libtuning/ctt_awb.py
> +++ b/utils/tuning/libtuning/ctt_awb.py
> @@ -302,10 +302,10 @@ def get_alsc_patches(Img, colour_cals,
> grey=True):
>      patches for each channel, remembering to subtract blacklevel
>      If grey then only greyscale patches considered
>      """
> +    patches = Img.patches
>      if grey:
>          cen_coords = Img.cen_coords[3::4]
>          col = Img.color
> -        patches = [np.array(Img.patches[i]) for i in Img.order]
>          r_patchs = patches[0][3::4] - Img.blacklevel_16
>          b_patchs = patches[3][3::4] - Img.blacklevel_16
>          """
> @@ -315,7 +315,6 @@ def get_alsc_patches(Img, colour_cals,
> grey=True):
>      else:
>          cen_coords = Img.cen_coords
>          col = Img.color
> -        patches = [np.array(Img.patches[i]) for i in Img.order]
>          r_patchs = patches[0] - Img.blacklevel_16
>          b_patchs = patches[3] - Img.blacklevel_16
>          g_patchs = (patches[1]+patches[2])/2 - Img.blacklevel_16
> diff --git a/utils/tuning/libtuning/image.py
> b/utils/tuning/libtuning/image.py
> index c8911a0ff125..ecd334bdc67f 100644
> --- a/utils/tuning/libtuning/image.py
> +++ b/utils/tuning/libtuning/image.py
> @@ -135,6 +135,6 @@ class Image:
>  
>              all_patches.append(ch_patches)
>  
> -        self.patches = all_patches
> +        self.patches = np.array(all_patches)
>  
>          return not saturated

Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>

Best wishes,
Isaac
Laurent Pinchart Dec. 17, 2024, 3:41 p.m. UTC | #2
On Tue, Dec 17, 2024 at 03:59:35PM +0100, Stefan Klug wrote:
> Tuning fails for raw images that don't have the channels ordered in
> RGGB.  In 19dc8c28f63c ("utils: tuning: libtuning: Implement the core of
> libtuning") the channels of the image were reordered to RGGB
> unconditionally in _read_image_dng(). That change was not applied to the
> ctt_awb code, so that the channels were reordered twice. Fix by removing
> the double ordering.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  utils/tuning/libtuning/ctt_awb.py | 3 +--
>  utils/tuning/libtuning/image.py   | 2 +-
>  2 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/utils/tuning/libtuning/ctt_awb.py b/utils/tuning/libtuning/ctt_awb.py
> index 117612f2582a..240f37e644bb 100644
> --- a/utils/tuning/libtuning/ctt_awb.py
> +++ b/utils/tuning/libtuning/ctt_awb.py
> @@ -302,10 +302,10 @@ def get_alsc_patches(Img, colour_cals, grey=True):
>      patches for each channel, remembering to subtract blacklevel
>      If grey then only greyscale patches considered
>      """
> +    patches = Img.patches
>      if grey:
>          cen_coords = Img.cen_coords[3::4]
>          col = Img.color
> -        patches = [np.array(Img.patches[i]) for i in Img.order]
>          r_patchs = patches[0][3::4] - Img.blacklevel_16
>          b_patchs = patches[3][3::4] - Img.blacklevel_16
>          """
> @@ -315,7 +315,6 @@ def get_alsc_patches(Img, colour_cals, grey=True):
>      else:
>          cen_coords = Img.cen_coords
>          col = Img.color
> -        patches = [np.array(Img.patches[i]) for i in Img.order]
>          r_patchs = patches[0] - Img.blacklevel_16
>          b_patchs = patches[3] - Img.blacklevel_16
>          g_patchs = (patches[1]+patches[2])/2 - Img.blacklevel_16
> diff --git a/utils/tuning/libtuning/image.py b/utils/tuning/libtuning/image.py
> index c8911a0ff125..ecd334bdc67f 100644
> --- a/utils/tuning/libtuning/image.py
> +++ b/utils/tuning/libtuning/image.py
> @@ -135,6 +135,6 @@ class Image:
>  
>              all_patches.append(ch_patches)
>  
> -        self.patches = all_patches
> +        self.patches = np.array(all_patches)
>  
>          return not saturated

Patch
diff mbox series

diff --git a/utils/tuning/libtuning/ctt_awb.py b/utils/tuning/libtuning/ctt_awb.py
index 117612f2582a..240f37e644bb 100644
--- a/utils/tuning/libtuning/ctt_awb.py
+++ b/utils/tuning/libtuning/ctt_awb.py
@@ -302,10 +302,10 @@  def get_alsc_patches(Img, colour_cals, grey=True):
     patches for each channel, remembering to subtract blacklevel
     If grey then only greyscale patches considered
     """
+    patches = Img.patches
     if grey:
         cen_coords = Img.cen_coords[3::4]
         col = Img.color
-        patches = [np.array(Img.patches[i]) for i in Img.order]
         r_patchs = patches[0][3::4] - Img.blacklevel_16
         b_patchs = patches[3][3::4] - Img.blacklevel_16
         """
@@ -315,7 +315,6 @@  def get_alsc_patches(Img, colour_cals, grey=True):
     else:
         cen_coords = Img.cen_coords
         col = Img.color
-        patches = [np.array(Img.patches[i]) for i in Img.order]
         r_patchs = patches[0] - Img.blacklevel_16
         b_patchs = patches[3] - Img.blacklevel_16
         g_patchs = (patches[1]+patches[2])/2 - Img.blacklevel_16
diff --git a/utils/tuning/libtuning/image.py b/utils/tuning/libtuning/image.py
index c8911a0ff125..ecd334bdc67f 100644
--- a/utils/tuning/libtuning/image.py
+++ b/utils/tuning/libtuning/image.py
@@ -135,6 +135,6 @@  class Image:
 
             all_patches.append(ch_patches)
 
-        self.patches = all_patches
+        self.patches = np.array(all_patches)
 
         return not saturated