Commit faccb5a
Fix clipping boxes with large coordinates (#9047)
Fixes #9045.
### Description
`spatial_crop_boxes` converted crop ROI bounds to `torch.int16`, which
overflows for coordinates above 32767. This could cause valid boxes in
large images to be clamped incorrectly and silently removed when
`remove_empty=True`.
This PR keeps the ROI bounds in the same tensor dtype as the boxes
during clipping and adds a regression test covering both
`spatial_crop_boxes` and the public `clip_boxes_to_image` path for large
coordinates.
### Types of changes
- [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).
- [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`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.
Local validation:
- `python -m tests.data.test_box_utils`
- `python -m ruff check monai/data/box_utils.py
tests/data/test_box_utils.py`
`black` and `isort` were not installed in my local Python environment,
so I could not run those checks directly.
---------
Signed-off-by: Rajioba1 <raji.lukmon@gmail.com>
Co-authored-by: Vikash Gupta <write2vikash@gmail.com>1 parent 87060c4 commit faccb5a
2 files changed
Lines changed: 17 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1035 | 1035 | | |
1036 | 1036 | | |
1037 | 1037 | | |
1038 | | - | |
1039 | | - | |
| 1038 | + | |
| 1039 | + | |
1040 | 1040 | | |
1041 | 1041 | | |
1042 | 1042 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
272 | 287 | | |
273 | 288 | | |
274 | 289 | | |
| |||
0 commit comments