[v2,11/25] libtuning: Reactivate macbeth locator
diff mbox series

Message ID 20240628104828.2928109-12-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • Add ccm calibration to libtuning
Related show

Commit Message

Stefan Klug June 28, 2024, 10:47 a.m. UTC
Add the missing pieces and store the result inside the image object.

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

Comments

Laurent Pinchart June 28, 2024, 11:09 p.m. UTC | #1
Hi Stefan,

Thank you for the patch.

On Fri, Jun 28, 2024 at 12:47:04PM +0200, Stefan Klug wrote:
> Add the missing pieces and store the result inside the image object.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> ---
>  utils/tuning/libtuning/image.py   |  1 +
>  utils/tuning/libtuning/macbeth.py | 13 ++++++++++---
>  utils/tuning/libtuning/utils.py   |  5 +++--
>  3 files changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/utils/tuning/libtuning/image.py b/utils/tuning/libtuning/image.py
> index 2c4d774f11e2..c8911a0ff125 100644
> --- a/utils/tuning/libtuning/image.py
> +++ b/utils/tuning/libtuning/image.py
> @@ -24,6 +24,7 @@ class Image:
>          self.lsc_only = False
>          self.color = -1
>          self.lux = -1
> +        self.macbeth = None
>  
>          try:
>              self._load_metadata_exif()
> diff --git a/utils/tuning/libtuning/macbeth.py b/utils/tuning/libtuning/macbeth.py
> index 28051de8155c..4a2006b013dc 100644
> --- a/utils/tuning/libtuning/macbeth.py
> +++ b/utils/tuning/libtuning/macbeth.py
> @@ -17,12 +17,15 @@ import logging
>  from sklearn import cluster as cluster
>  
>  from .ctt_ransac import get_square_verts, get_square_centres
> -
> -from libtuning.image import Image
> +from .image import Image
>  
>  logger = logging.getLogger(__name__)
>  
>  
> +class MacbethError(Exception):
> +    pass
> +
> +
>  # Reshape image to fixed width without distorting returns image and scale
>  # factor
>  def reshape(img, width):
> @@ -377,7 +380,9 @@ def get_macbeth_chart(img, ref_data):
>  
>      # Catch macbeth errors and continue with code
>      except MacbethError as error:
> -        logger.warning(error)
> +        # \todo: This happens so many times in a normal run, that it shadows
> +        # all the relevant output
> +        # logger.warning(error)
>          return (0, None, None, False)
>  
>  
> @@ -527,4 +532,6 @@ def locate_macbeth(image: Image, config: dict):
>          logger.warning(f'Macbeth patches have saturated in {image.path.name}')
>          return None
>  
> +    image.macbeth = macbeth
> +
>      return macbeth
> diff --git a/utils/tuning/libtuning/utils.py b/utils/tuning/libtuning/utils.py
> index 00cf5a57512f..1e7991e84a70 100644
> --- a/utils/tuning/libtuning/utils.py
> +++ b/utils/tuning/libtuning/utils.py
> @@ -17,7 +17,7 @@ import logging
>  
>  import libtuning as lt
>  from libtuning.image import Image
> -from libtuning.macbeth import locate_macbeth
> +from .macbeth import locate_macbeth
>  
>  logger = logging.getLogger(__name__)
>  
> @@ -92,6 +92,7 @@ def load_images(input_dir: str, config: dict, load_nonlsc: bool, load_lsc: bool)
>      images = []
>      for f in files:
>          color, lux, lsc_only = _parse_image_filename(f)
> +        logger.info(f'Process image {f.name} (color={color}, lux={lux}, lsc_only={lsc_only})')

Should this go after the color check ?

>          if color is None:

And should an error be reported here ?

This hunk seems to be a candidate for a separate patch.

>              continue
>  
> @@ -127,7 +128,7 @@ def load_images(input_dir: str, config: dict, load_nonlsc: bool, load_lsc: bool)
>              continue
>  
>          # Handle macbeth
> -        macbeth = locate_macbeth(config)
> +        macbeth = locate_macbeth(image, config)
>          if macbeth is None:
>              continue
>

Patch
diff mbox series

diff --git a/utils/tuning/libtuning/image.py b/utils/tuning/libtuning/image.py
index 2c4d774f11e2..c8911a0ff125 100644
--- a/utils/tuning/libtuning/image.py
+++ b/utils/tuning/libtuning/image.py
@@ -24,6 +24,7 @@  class Image:
         self.lsc_only = False
         self.color = -1
         self.lux = -1
+        self.macbeth = None
 
         try:
             self._load_metadata_exif()
diff --git a/utils/tuning/libtuning/macbeth.py b/utils/tuning/libtuning/macbeth.py
index 28051de8155c..4a2006b013dc 100644
--- a/utils/tuning/libtuning/macbeth.py
+++ b/utils/tuning/libtuning/macbeth.py
@@ -17,12 +17,15 @@  import logging
 from sklearn import cluster as cluster
 
 from .ctt_ransac import get_square_verts, get_square_centres
-
-from libtuning.image import Image
+from .image import Image
 
 logger = logging.getLogger(__name__)
 
 
+class MacbethError(Exception):
+    pass
+
+
 # Reshape image to fixed width without distorting returns image and scale
 # factor
 def reshape(img, width):
@@ -377,7 +380,9 @@  def get_macbeth_chart(img, ref_data):
 
     # Catch macbeth errors and continue with code
     except MacbethError as error:
-        logger.warning(error)
+        # \todo: This happens so many times in a normal run, that it shadows
+        # all the relevant output
+        # logger.warning(error)
         return (0, None, None, False)
 
 
@@ -527,4 +532,6 @@  def locate_macbeth(image: Image, config: dict):
         logger.warning(f'Macbeth patches have saturated in {image.path.name}')
         return None
 
+    image.macbeth = macbeth
+
     return macbeth
diff --git a/utils/tuning/libtuning/utils.py b/utils/tuning/libtuning/utils.py
index 00cf5a57512f..1e7991e84a70 100644
--- a/utils/tuning/libtuning/utils.py
+++ b/utils/tuning/libtuning/utils.py
@@ -17,7 +17,7 @@  import logging
 
 import libtuning as lt
 from libtuning.image import Image
-from libtuning.macbeth import locate_macbeth
+from .macbeth import locate_macbeth
 
 logger = logging.getLogger(__name__)
 
@@ -92,6 +92,7 @@  def load_images(input_dir: str, config: dict, load_nonlsc: bool, load_lsc: bool)
     images = []
     for f in files:
         color, lux, lsc_only = _parse_image_filename(f)
+        logger.info(f'Process image {f.name} (color={color}, lux={lux}, lsc_only={lsc_only})')
         if color is None:
             continue
 
@@ -127,7 +128,7 @@  def load_images(input_dir: str, config: dict, load_nonlsc: bool, load_lsc: bool)
             continue
 
         # Handle macbeth
-        macbeth = locate_macbeth(config)
+        macbeth = locate_macbeth(image, config)
         if macbeth is None:
             continue