[v2,08/25] libtuning: Fix visualize_macbeth_chart()
diff mbox series

Message ID 20240628104828.2928109-9-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
The old function uses PIL to save the image, which is not in the
requirements file. As we are already requiring opencv, use that to save
images instead of an additional dependency

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
---
 utils/tuning/libtuning/utils.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

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

Thank you for the patch.

On Fri, Jun 28, 2024 at 12:47:01PM +0200, Stefan Klug wrote:
> The old function uses PIL to save the image, which is not in the
> requirements file. As we are already requiring opencv, use that to save
> images instead of an additional dependency
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
> ---
>  utils/tuning/libtuning/utils.py | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/utils/tuning/libtuning/utils.py b/utils/tuning/libtuning/utils.py
> index 872341407b7b..178c6957c581 100644
> --- a/utils/tuning/libtuning/utils.py
> +++ b/utils/tuning/libtuning/utils.py
> @@ -7,6 +7,7 @@
>  
>  import decimal
>  import math
> +import cv2

Alphabetic order.

>  import numpy as np
>  import os
>  from pathlib import Path
> @@ -162,6 +163,6 @@ def visualise_macbeth_chart(macbeth_rgb, original_rgb, new_rgb, output_filename)
>                  for g in range(100):
>                      image[xlocation + i, ylocation + g] = new_rgb[colorindex]
>  
> -    img = Image.fromarray(image, 'RGB')
> -    img.save(str(output_filename) + 'Generated Macbeth Chart.png')
> +    im_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
> +    cv2.imwrite(f'{output_filename} Generated Macbeth Chart.png', im_bgr)
>  

At some point we should create a better Image class that will handle all
of this. At some point :-)

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

Patch
diff mbox series

diff --git a/utils/tuning/libtuning/utils.py b/utils/tuning/libtuning/utils.py
index 872341407b7b..178c6957c581 100644
--- a/utils/tuning/libtuning/utils.py
+++ b/utils/tuning/libtuning/utils.py
@@ -7,6 +7,7 @@ 
 
 import decimal
 import math
+import cv2
 import numpy as np
 import os
 from pathlib import Path
@@ -162,6 +163,6 @@  def visualise_macbeth_chart(macbeth_rgb, original_rgb, new_rgb, output_filename)
                 for g in range(100):
                     image[xlocation + i, ylocation + g] = new_rgb[colorindex]
 
-    img = Image.fromarray(image, 'RGB')
-    img.save(str(output_filename) + 'Generated Macbeth Chart.png')
+    im_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
+    cv2.imwrite(f'{output_filename} Generated Macbeth Chart.png', im_bgr)