Skip to content

Commit c10cdd2

Browse files
authored
Change default dtype value in Watershed and GenerateWatershedMarkers (#5732)
Fixes #. ### Description - When the image is large, the number of instances may exceed np.uint8, so the default dtype should set to `np.int64` - a workaround way to add `FillHoles` before `generate_instance_contour`, may prevent the issue when instances contain hole ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: KumoLiu <yunl@nvidia.com>
1 parent ae89327 commit c10cdd2

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

  • monai/apps/pathology/transforms/post

monai/apps/pathology/transforms/post/array.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ class Watershed(Transform):
6161
connectivity: an array with the same number of dimensions as image whose non-zero elements indicate
6262
neighbors for connection. Following the scipy convention, default is a one-connected array of
6363
the dimension of the image.
64-
dtype: target data content type to convert, default is np.uint8.
64+
dtype: target data content type to convert, default is np.int64.
6565
6666
"""
6767

6868
backend = [TransformBackends.NUMPY]
6969

70-
def __init__(self, connectivity: Optional[int] = 1, dtype: DtypeLike = np.uint8) -> None:
70+
def __init__(self, connectivity: Optional[int] = 1, dtype: DtypeLike = np.int64) -> None:
7171
self.connectivity = connectivity
7272
self.dtype = dtype
7373

@@ -292,7 +292,7 @@ class GenerateWatershedMarkers(Transform):
292292
min_object_size: objects smaller than this size (in pixel) are removed. Defaults to 10.
293293
postprocess_fn: additional post-process function on the markers.
294294
If not provided, :py:class:`monai.transforms.post.FillHoles()` will be used.
295-
dtype: target data type to convert to. Defaults to np.uint8.
295+
dtype: target data type to convert to. Defaults to np.int64.
296296
297297
"""
298298

@@ -304,7 +304,7 @@ def __init__(
304304
radius: int = 2,
305305
min_object_size: int = 10,
306306
postprocess_fn: Optional[Callable] = None,
307-
dtype: DtypeLike = np.uint8,
307+
dtype: DtypeLike = np.int64,
308308
) -> None:
309309
self.threshold = threshold
310310
self.radius = radius
@@ -728,7 +728,7 @@ def __call__( # type: ignore
728728
:, instance_bbox[0][0] : instance_bbox[0][1], instance_bbox[0][2] : instance_bbox[0][3]
729729
]
730730
offset = [instance_bbox[0][2], instance_bbox[0][0]]
731-
instance_contour = self.generate_instance_contour(instance_mask, offset)
731+
instance_contour = self.generate_instance_contour(FillHoles()(instance_mask), offset)
732732
if instance_contour is not None:
733733
instance_centroid = self.generate_instance_centroid(instance_mask, offset)
734734
instance_info[inst_id] = {

0 commit comments

Comments
 (0)