From 1d338628b331420a8f45bddd5ac75ce466039407 Mon Sep 17 00:00:00 2001 From: Constantin Pape Date: Fri, 26 Jul 2024 15:10:32 +0200 Subject: [PATCH] Fix issue with dtypes that leads to integer overflow in committing (#671) --- micro_sam/sam_annotator/_widgets.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/micro_sam/sam_annotator/_widgets.py b/micro_sam/sam_annotator/_widgets.py index 4822dc37..50a190e0 100644 --- a/micro_sam/sam_annotator/_widgets.py +++ b/micro_sam/sam_annotator/_widgets.py @@ -350,7 +350,10 @@ def _commit_impl(viewer, layer, preserve_committed): z_min, z_max = state.z_range bb = np.s_[z_min:(z_max+1)] - seg = viewer.layers[layer].data[bb] + # Cast the dtype of the segmentation we work with correctly. + # Otherwise we run into type conversion errors later. + dtype = viewer.layers["committed_objects"].data.dtype + seg = viewer.layers[layer].data[bb].astype(dtype) shape = seg.shape # We parallelize these operatios because they take quite long for large volumes.