[v3,04/23] libtuning: Copy visualize_macbeth_chart from raspberry pi
diff mbox series

Message ID 20240703141726.252368-5-stefan.klug@ideasonboard.com
State Superseded
Headers show
Series
  • Add ccm calibration to libtuning
Related show

Commit Message

Stefan Klug July 3, 2024, 2:16 p.m. UTC
Copy visualize_macbeth_chart from raspberry pi.  It is copied verbatim
and does not work in this state.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 utils/tuning/libtuning/utils.py | 43 +++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Comments

Paul Elder July 4, 2024, 8:59 a.m. UTC | #1
On Wed, Jul 03, 2024 at 04:16:53PM +0200, Stefan Klug wrote:
> Copy visualize_macbeth_chart from raspberry pi.  It is copied verbatim
> and does not work in this state.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Acked-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  utils/tuning/libtuning/utils.py | 43 +++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/utils/tuning/libtuning/utils.py b/utils/tuning/libtuning/utils.py
> index 1e8128ea0571..f099c0ed685c 100644
> --- a/utils/tuning/libtuning/utils.py
> +++ b/utils/tuning/libtuning/utils.py
> @@ -123,3 +123,46 @@ def load_images(input_dir: str, config: dict, load_nonlsc: bool, load_lsc: bool)
>          return None
>  
>      return images
> +
> +
> +
> +"""
> +Some code that will save virtual macbeth charts that show the difference between optimised matrices and non optimised matrices
> +
> +The function creates an image that is 1550 by 1050 pixels wide, and fills it with patches which are 200x200 pixels in size
> +Each patch contains the ideal color, the color from the original matrix, and the color from the final matrix
> +_________________
> +|               |
> +|  Ideal Color  |
> +|_______________|
> +|  Old  |  new  |
> +| Color | Color |
> +|_______|_______|
> +
> +Nice way of showing how the optimisation helps change the colors and the color matricies
> +"""
> +def visualise_macbeth_chart(macbeth_rgb, original_rgb, new_rgb, output_filename):
> +    image = np.zeros((1050, 1550, 3), dtype=np.uint8)
> +    colorindex = -1
> +    for y in range(6):
> +        for x in range(4):  # Creates 6 x 4 grid of macbeth chart
> +            colorindex += 1
> +            xlocation = 50 + 250 * x  # Means there is 50px of black gap between each square, more like the real macbeth chart.
> +            ylocation = 50 + 250 * y
> +            for g in range(200):
> +                for i in range(100):
> +                    image[xlocation + i, ylocation + g] = macbeth_rgb[colorindex]
> +            xlocation = 150 + 250 * x
> +            ylocation = 50 + 250 * y
> +            for i in range(100):
> +                for g in range(100):
> +                    image[xlocation + i, ylocation + g] = original_rgb[colorindex]  # Smaller squares below to compare the old colors with the new ones
> +            xlocation = 150 + 250 * x
> +            ylocation = 150 + 250 * y
> +            for i in range(100):
> +                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')
> +
> -- 
> 2.43.0
>

Patch
diff mbox series

diff --git a/utils/tuning/libtuning/utils.py b/utils/tuning/libtuning/utils.py
index 1e8128ea0571..f099c0ed685c 100644
--- a/utils/tuning/libtuning/utils.py
+++ b/utils/tuning/libtuning/utils.py
@@ -123,3 +123,46 @@  def load_images(input_dir: str, config: dict, load_nonlsc: bool, load_lsc: bool)
         return None
 
     return images
+
+
+
+"""
+Some code that will save virtual macbeth charts that show the difference between optimised matrices and non optimised matrices
+
+The function creates an image that is 1550 by 1050 pixels wide, and fills it with patches which are 200x200 pixels in size
+Each patch contains the ideal color, the color from the original matrix, and the color from the final matrix
+_________________
+|               |
+|  Ideal Color  |
+|_______________|
+|  Old  |  new  |
+| Color | Color |
+|_______|_______|
+
+Nice way of showing how the optimisation helps change the colors and the color matricies
+"""
+def visualise_macbeth_chart(macbeth_rgb, original_rgb, new_rgb, output_filename):
+    image = np.zeros((1050, 1550, 3), dtype=np.uint8)
+    colorindex = -1
+    for y in range(6):
+        for x in range(4):  # Creates 6 x 4 grid of macbeth chart
+            colorindex += 1
+            xlocation = 50 + 250 * x  # Means there is 50px of black gap between each square, more like the real macbeth chart.
+            ylocation = 50 + 250 * y
+            for g in range(200):
+                for i in range(100):
+                    image[xlocation + i, ylocation + g] = macbeth_rgb[colorindex]
+            xlocation = 150 + 250 * x
+            ylocation = 50 + 250 * y
+            for i in range(100):
+                for g in range(100):
+                    image[xlocation + i, ylocation + g] = original_rgb[colorindex]  # Smaller squares below to compare the old colors with the new ones
+            xlocation = 150 + 250 * x
+            ylocation = 150 + 250 * y
+            for i in range(100):
+                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')
+