From 55b7398df53d2b4e4d6c4d4fb26e254b8f3410b6 Mon Sep 17 00:00:00 2001 From: William Silversmith Date: Sat, 22 Jun 2024 02:39:01 -0400 Subject: [PATCH] fix+test: use uint16 for small dimensions for 2d --- automated_test.py | 18 ++++++++++++++++++ cc3d.pyx | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/automated_test.py b/automated_test.py index ff093ee..40504a6 100644 --- a/automated_test.py +++ b/automated_test.py @@ -1039,6 +1039,24 @@ def test_statistics_big(order): assert stats["voxel_counts"][1] == 100 assert stats["voxel_counts"][2] == 10 * 10 * 1 + # test 2d + + labels = np.zeros((50,66000), dtype=np.uint8, order=order) + labels[10:20,10:20] = 1 + labels[40:50,40:50] = 2 + + stats = cc3d.statistics(labels) + assert stats["voxel_counts"][1] == 100 + assert stats["voxel_counts"][2] == 10 * 10 + + labels = np.zeros((66000,60), dtype=np.uint8, order=order) + labels[10:20,10:20] = 1 + labels[40:50,40:50] = 2 + + stats = cc3d.statistics(labels) + assert stats["voxel_counts"][1] == 100 + assert stats["voxel_counts"][2] == 10 * 10 + @pytest.mark.parametrize("connectivity", (8, 18, 26)) @pytest.mark.parametrize("dtype", TEST_TYPES) @pytest.mark.parametrize("order", ("C", "F")) diff --git a/cc3d.pyx b/cc3d.pyx index 41a8c35..9a248be 100644 --- a/cc3d.pyx +++ b/cc3d.pyx @@ -702,8 +702,8 @@ def statistics( return _statistics_helper3d(out_labels, no_slice_conversion, bounding_boxes32, N) else: if out_labels.ndim == 2: - bounding_boxes32 = np.zeros(4 * (N + 1), dtype=np.uint32) - return _statistics_helper2d(out_labels, no_slice_conversion, bounding_boxes32, N) + bounding_boxes16 = np.zeros(4 * (N + 1), dtype=np.uint16) + return _statistics_helper2d(out_labels, no_slice_conversion, bounding_boxes16, N) else: bounding_boxes16 = np.zeros(6 * (N + 1), dtype=np.uint16) return _statistics_helper3d(out_labels, no_slice_conversion, bounding_boxes16, N)