From edd05e914f1c2556e0611b98dc7a9c30d5130312 Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Wed, 5 Jun 2024 17:06:57 +0200 Subject: [PATCH 1/2] Fix error when passing a boolean mask When passing a boolean mask to `add_modality` (which is supported according to the type hints) using ```python mask = np.zeros((3000, 3000), dtype="uint8") mask [ 500:-500, 20:-500] = 1 ``` It failed with ```pytb File /python3.10/site-packages/wsireg/reg_images/tifffile_reg_image.py:46, in TiffFileRegImage.__init__(self, image_fp, image_res, mask, pre_reg_transforms, preprocessing, channel_names, channel_colors) 42 self._get_dim_info() 44 self._dask_image = self._get_dask_image() ---> 46 if mask: 47 self._mask = self.read_mask(mask) 49 self.pre_reg_transforms = pre_reg_transforms ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() ``` The fix is simple: check `if mask is None:` instead of `if mask:`. --- wsireg/reg_images/sitk_reg_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsireg/reg_images/sitk_reg_image.py b/wsireg/reg_images/sitk_reg_image.py index c5f01c0..b7a3d16 100644 --- a/wsireg/reg_images/sitk_reg_image.py +++ b/wsireg/reg_images/sitk_reg_image.py @@ -36,7 +36,7 @@ def __init__( self._n_ch = self._shape[2] if self.is_rgb else self._shape[0] - if mask: + if mask is not None: self._mask = self.read_mask(mask) self.pre_reg_transforms = pre_reg_transforms From bb3cdd3cb27d7c8bcc9f03b9a4619012af0b3f9c Mon Sep 17 00:00:00 2001 From: Gregor Sturm Date: Wed, 5 Jun 2024 15:15:21 +0000 Subject: [PATCH 2/2] Fix also in other places --- wsireg/reg_images/czi_reg_image.py | 2 +- wsireg/reg_images/tifffile_reg_image.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wsireg/reg_images/czi_reg_image.py b/wsireg/reg_images/czi_reg_image.py index 208f380..ae3a9fc 100644 --- a/wsireg/reg_images/czi_reg_image.py +++ b/wsireg/reg_images/czi_reg_image.py @@ -42,7 +42,7 @@ def __init__( self._dask_image = self._prepare_dask_image() - if mask: + if mask is not None: self._mask = self.read_mask(mask) self.pre_reg_transforms = pre_reg_transforms diff --git a/wsireg/reg_images/tifffile_reg_image.py b/wsireg/reg_images/tifffile_reg_image.py index 1f4d14f..461cccb 100644 --- a/wsireg/reg_images/tifffile_reg_image.py +++ b/wsireg/reg_images/tifffile_reg_image.py @@ -43,7 +43,7 @@ def __init__( self._dask_image = self._get_dask_image() - if mask: + if mask is not None: self._mask = self.read_mask(mask) self.pre_reg_transforms = pre_reg_transforms