Skip to content

Commit

Permalink
Merge pull request #2211 from camptocamp/use-background-color
Browse files Browse the repository at this point in the history
Get the background color from the generated image
  • Loading branch information
sbrunner committed Apr 10, 2024
2 parents 8703eeb + 5311927 commit f50825c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions c2cwsgiutils/acceptance/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def normalize_image(image: NpNdarrayInt) -> NpNdarrayInt:
return image


def check_image(
def check_image( # pylint: disable=too-many-locals,too-many-statements
result_folder: str,
image_to_check: NpNdarrayInt,
expected_filename: str,
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit f50825c

Please sign in to comment.