Repository navigation
Commit 2c54111
Fix per_component Dice silently ignoring ignore_index (#9171)
### Description
`DiceHelper`/`DiceMetric`'s `per_component=True` path never received the
spatial mask `create_ignore_mask` builds from `ignore_index` —
`compute_cc_dice` has no mask parameter at all, so combining
`per_component=True` with `ignore_index` silently computed TP/FP/FN over
the "ignored" voxels as if nothing were ignored. The regular per-channel
path already applies this mask correctly; only the per-component path
was missing it.
Fix threads the mask into `compute_cc_dice`: ignored voxels are forced
to agree as background in both `y` and `y_pred` before the
connected-component assignment and histogram, so they never contribute
to any component's score — consistent with how the non-per_component
path already handles masking.
Reachable via the public API: `DiceMetric(per_component=True,
ignore_index=N)(y_pred, y)`. No existing test exercised this combination
(checked `tests/metrics/test_compute_meandice.py` — separate
`per_component` and `ignore_index` cases, never together).
### Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] 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` (ran the targeted test file directly via pytest
instead: `pytest tests/metrics/test_compute_meandice.py`, 22/22 passed;
did not run the full repo test runner)
- [ ] In-line docstrings updated
- [ ] Documentation updated
---------
Signed-off-by: Siddhardha Nanda <99672439+SID-6921@users.noreply.github.com>
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>1 parent e0cee14 commit 2c54111
2 files changed
Lines changed: 30 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
334 | | - | |
| 334 | + | |
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
341 | 345 | | |
342 | 346 | | |
343 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
344 | 351 | | |
345 | 352 | | |
346 | 353 | | |
347 | 354 | | |
348 | 355 | | |
349 | 356 | | |
350 | 357 | | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
351 | 362 | | |
352 | 363 | | |
353 | 364 | | |
| |||
445 | 456 | | |
446 | 457 | | |
447 | 458 | | |
448 | | - | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
449 | 463 | | |
450 | 464 | | |
451 | 465 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
293 | 306 | | |
294 | 307 | | |
295 | 308 | | |
| |||
342 | 355 | | |
343 | 356 | | |
344 | 357 | | |
345 | | - | |
| 358 | + | |
346 | 359 | | |
347 | 360 | | |
348 | 361 | | |
| |||
0 commit comments