NHPatterson / wsireg

multimodal whole slide image registration in a graph structure
MIT License
76 stars 7 forks source link

Fix error when passing a boolean mask #73

Open grst opened 3 months ago

grst commented 3 months ago

When passing a boolean mask to add_modality (which is supported according to the type hints) using

mask = np.zeros((3000, 3000), dtype="uint8")
mask [ 500:-500, 20:-500] = 1

It failed with

File <redacted>/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:.

NHPatterson commented 3 months ago

Thanks for this fix, after it builds I will merge and bump version so it deploys to pip.