From 3b3494b6f0068572575d700350672042997a6f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 8 Apr 2024 16:00:52 +0200 Subject: [PATCH] Get the background color from the generated image Nice for image in dark mode --- c2cwsgiutils/acceptance/image.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/c2cwsgiutils/acceptance/image.py b/c2cwsgiutils/acceptance/image.py index 95cc79ac0..ae3d9a50a 100644 --- a/c2cwsgiutils/acceptance/image.py +++ b/c2cwsgiutils/acceptance/image.py @@ -108,6 +108,13 @@ def check_image( mask = None if mask_filename is not None: + background_color = [255, 255, 255] + for color in range(3): + img_hist, _ = skimage.exposure.histogram( + image_to_check[..., color], nbins=256, source_range="dtype" + ) + background_color[color] = np.argmax(img_hist) + mask = skimage.io.imread(mask_filename) assert mask is not None, "Wrong mask: " + mask_filename @@ -130,7 +137,7 @@ def check_image( assert ( mask.shape[0] == image_to_check.shape[0] and mask.shape[1] == image_to_check.shape[1] ), f"Mask and image should have the same shape ({mask.shape} != {image_to_check.shape})" - image_to_check[mask] = [255, 255, 255] + image_to_check[mask] = background_color if not os.path.exists(result_folder): os.makedirs(result_folder) @@ -148,7 +155,7 @@ def check_image( assert ( expected.shape[0] == mask.shape[0] and expected.shape[1] == mask.shape[1] ), f"Mask and expected image should have the same shape ({mask.shape} != {expected.shape})" - expected[mask] = [255, 255, 255] + expected[mask] = background_color assert ( expected.shape == image_to_check.shape