Skip to content

Commit 35db359

Browse files
authored
Add warning in GenerateSuccinctContour (#5752)
Signed-off-by: KumoLiu <[email protected]> Fixes #5714. ### Description Add warning in `GenerateSuccinctContour` and skip invalid instance. ### 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 <[email protected]>
1 parent 5f6cb2d commit 35db359

File tree

1 file changed

+6
-1
lines changed
  • monai/apps/pathology/transforms/post

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# See the License for the specific language governing permissions and
1010
# limitations under the License.
1111

12+
import warnings
1213
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union
1314

1415
import numpy as np
@@ -458,6 +459,9 @@ def __call__(self, contours: List[np.ndarray]) -> np.ndarray:
458459
elif coord[1] == self.width - 1:
459460
corner = 2
460461
pixel = (int(coord[0] - 0.5), int(coord[1]))
462+
else:
463+
warnings.warn(f"Invalid contour coord {coord} is generated, skip this instance.")
464+
return None # type: ignore
461465
sequence.append(pixel)
462466
last_added = pixel
463467
elif i == len(group) - 1:
@@ -555,7 +559,8 @@ def __call__(self, inst_mask: NdarrayOrTensor, offset: Optional[Sequence[int]] =
555559
inst_contour_cv = find_contours(inst_mask, level=self.contour_level)
556560
generate_contour = GenerateSuccinctContour(inst_mask.shape[0], inst_mask.shape[1])
557561
inst_contour = generate_contour(inst_contour_cv)
558-
562+
if inst_contour is None:
563+
return None
559564
# less than `self.min_num_points` points don't make a contour, so skip.
560565
# They are likely to be artifacts as the contours obtained via approximation.
561566
if inst_contour.shape[0] < self.min_num_points:

0 commit comments

Comments
 (0)