From d3cea5e3d6d5648a18cd0ef6aa2fcce91ffe4763 Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Sat, 3 Jan 2026 11:35:02 +0100 Subject: [PATCH 1/5] Extend `_get_image_labels` to handle boolean labels --- lib/galaxy/tool_util/verify/asserts/image.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/verify/asserts/image.py b/lib/galaxy/tool_util/verify/asserts/image.py index daf4ab8e70c..2da7320bbcc 100644 --- a/lib/galaxy/tool_util/verify/asserts/image.py +++ b/lib/galaxy/tool_util/verify/asserts/image.py @@ -747,8 +747,14 @@ def _get_image_labels( label = label.strip() if numpy.issubdtype(im_arr.dtype, numpy.integer): return int(label) - if numpy.issubdtype(im_arr.dtype, float): + if numpy.issubdtype(im_arr.dtype, numpy.floating): return float(label) + if numpy.issubdtype(im_arr.dtype, bool): + label_lower = label.lower() + if label_lower in ('0', '1', 'false', 'true'): + return label_lower in ('1', 'true') + else: + raise AssertionError(f'Label "{label}" incompatible with label type "{im_arr.dtype}"') raise AssertionError(f'Unsupported image label type: "{im_arr.dtype}"') # Determine labels present in the image. From 07afc1010783c8951b7cc685b6bfdebe4444dafb Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Sat, 3 Jan 2026 11:43:44 +0100 Subject: [PATCH 2/5] Fix string quotes in boolean label check --- lib/galaxy/tool_util/verify/asserts/image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/tool_util/verify/asserts/image.py b/lib/galaxy/tool_util/verify/asserts/image.py index 2da7320bbcc..4bbedbc324d 100644 --- a/lib/galaxy/tool_util/verify/asserts/image.py +++ b/lib/galaxy/tool_util/verify/asserts/image.py @@ -751,8 +751,8 @@ def _get_image_labels( return float(label) if numpy.issubdtype(im_arr.dtype, bool): label_lower = label.lower() - if label_lower in ('0', '1', 'false', 'true'): - return label_lower in ('1', 'true') + if label_lower in ("0", "1", "false", "true"): + return label_lower in ("1", "true") else: raise AssertionError(f'Label "{label}" incompatible with label type "{im_arr.dtype}"') raise AssertionError(f'Unsupported image label type: "{im_arr.dtype}"') From 329d130b7f9380a96eb4c8033a60b7825fb4286e Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Sat, 3 Jan 2026 11:59:13 +0100 Subject: [PATCH 3/5] Add test for content assertions with `bool` image --- test-data/im3_b_bool.tiff | Bin 0 -> 368 bytes test/functional/tools/validation_image.xml | 14 ++++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test-data/im3_b_bool.tiff diff --git a/test-data/im3_b_bool.tiff b/test-data/im3_b_bool.tiff new file mode 100644 index 0000000000000000000000000000000000000000..dceefdea1d2a310f7c560f7690b4b080d898f175 GIT binary patch literal 368 zcmebD)MDUZU|`^7U|?inU<9%hfS3`9&CJLQ76-|(LD@hi10N$3g9wmb1;m0-^&fz2 zQ6%+ZNalz`*$qH7QjDx%GtU9p(ops_AX@`TuOZNU9-!DgAO?YIrQ(dlf>b3dg=k|V p9R*{f*jk7L5(#o6GA_wXOH0elN!2T;gsS@gpMilAjAR*EOaM0CFzEmQ literal 0 HcmV?d00001 diff --git a/test/functional/tools/validation_image.xml b/test/functional/tools/validation_image.xml index c94c3581c3f..f1b139e55a2 100644 --- a/test/functional/tools/validation_image.xml +++ b/test/functional/tools/validation_image.xml @@ -181,6 +181,20 @@ + + + + + + + + + + + + + + From 1abfd2c204b116ba5e38b736c08ec2c6b529a2a8 Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Sat, 3 Jan 2026 12:13:52 +0100 Subject: [PATCH 4/5] Add unit test for `image_diff` with bool images (failing) --- test/unit/tool_util/test_verify.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/unit/tool_util/test_verify.py b/test/unit/tool_util/test_verify.py index fa814401527..523ae319756 100644 --- a/test/unit/tool_util/test_verify.py +++ b/test/unit/tool_util/test_verify.py @@ -87,6 +87,17 @@ F9 = _encode_image( ), format="PNG", ) +F10 = _encode_image( + numpy.array( + [ + [True, True, True], + [True, False, True], + [True, True, True], + ], + dtype=bool, + ), + format="TIFF", +) def _test_file_list(): @@ -102,6 +113,7 @@ def _test_file_list(): (F7, ".tiff"), (F8, ".tiff"), (F9, ".png"), + (F10, ".tiff"), ]: with tempfile.NamedTemporaryFile(mode="wb", suffix=ext, delete=False) as out: if ext == ".txt.gz": @@ -112,7 +124,7 @@ def _test_file_list(): def generate_tests(multiline=False): - f1, f2, f3, f4, multiline_match, f5, f6, f7, f8, f9 = _test_file_list() + f1, f2, f3, f4, multiline_match, f5, f6, f7, f8, f9, f10 = _test_file_list() tests: List[TestDef] if multiline: tests = [(multiline_match, f1, {"lines_diff": 0, "sort": True}, None)] @@ -130,7 +142,7 @@ def generate_tests(multiline=False): def generate_tests_sim_size(): - f1, f2, f3, f4, multiline_match, f5, f6, f7, f8, f9 = _test_file_list() + f1, f2, f3, f4, multiline_match, f5, f6, f7, f8, f9, f10 = _test_file_list() # tests for equal files tests: List[TestDef] = [ (f1, f1, None, None), # pass default values @@ -156,7 +168,7 @@ def generate_tests_sim_size(): def generate_tests_image_diff(): - f1, f2, f3, f4, multiline_match, f5, f6, f7, f8, f9 = _test_file_list() + f1, f2, f3, f4, multiline_match, f5, f6, f7, f8, f9, f10 = _test_file_list() metrics = ["mae", "mse", "rms", "fro", "iou"] # tests for equal files (uint8, PNG) tests: List[TestDef] = [(f6, f6, {"metric": metric}, None) for metric in metrics] @@ -164,6 +176,8 @@ def generate_tests_image_diff(): tests += [(f7, f7, {"metric": metric}, None) for metric in metrics] # tests for equal files (float, TIFF) tests += [(f8, f8, {"metric": metric}, None) for metric in metrics] + # tests for equal files (bool, TIFF) + tests += [(f10, f10, {"metric": metric}, None) for metric in metrics] # tests for pairs of different files tests += [(f6, f8, {"metric": metric}, AssertionError) for metric in metrics] # uint8 vs float tests += [(f7, f8, {"metric": metric}, AssertionError) for metric in metrics] # uint8 vs float From e804adeff38e1b78482b0cecdcc59abf3b04257c Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Wed, 7 Jan 2026 18:11:13 +0100 Subject: [PATCH 5/5] Fix for `bool` images` --- lib/galaxy/tool_util/verify/__init__.py | 6 ++++++ test/functional/tools/image_diff.xml | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/lib/galaxy/tool_util/verify/__init__.py b/lib/galaxy/tool_util/verify/__init__.py index cac554dd0b7..66dda2ceda4 100644 --- a/lib/galaxy/tool_util/verify/__init__.py +++ b/lib/galaxy/tool_util/verify/__init__.py @@ -595,6 +595,12 @@ def files_image_diff(file1: str, file2: str, attributes: Optional[Dict[str, Any] if arr1.shape != arr2.shape: raise AssertionError(f"Image dimensions did not match ({arr1.shape}, {arr2.shape}).") + # Handle `bool` images by converting them to `uint8` + if numpy.issubdtype(arr1.dtype, bool): + arr1 = arr1.astype(numpy.uint8) + if numpy.issubdtype(arr2.dtype, bool): + arr2 = arr2.astype(numpy.uint8) + distance = get_image_metric(attributes)(arr1, arr2) distance_eps = attributes.get("eps", DEFAULT_EPS) if distance > distance_eps: diff --git a/test/functional/tools/image_diff.xml b/test/functional/tools/image_diff.xml index addb4ef24b4..d6d9f9b1ffb 100644 --- a/test/functional/tools/image_diff.xml +++ b/test/functional/tools/image_diff.xml @@ -27,6 +27,11 @@ + + + + +