ShiftIntensity(safe=True) still wraps uint8 values when `offset` is an int
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 84/100
Direzione di ricerca
Leggi ShiftIntensity.__call__ in monai/transforms/intensity/array.py e i test in tests/transforms/test_shift_intensity*.py. Riproduci il caso segnalato con uint8 e offset interi e in virgola mobile. Aggiungi quindi test per safe=True e per le trasformazioni Random o Dictionary correlate, se i test esistenti consentono di farlo facilmente. Il lavoro è concluso quando gli offset interi producono i valori limitati previsti e i test passano.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
[Describe the bug
safe=True in ShiftIntensity (added for #5621) clamps overflow for float offsets but not for int offsets. With a uint8 image and an int offset, img + offset stays uint8, so values wrap during the addition, before convert_data_type(..., safe=True) runs (monai/transforms/intensity/array.py, ShiftIntensity.__call__). The safe check then has nothing to clamp. This also affects RandShiftIntensity and the dictionary versions, which use ShiftIntensity.
To Reproduce
import torch
from monai.transforms import ShiftIntensity
img = torch.tensor([0, 100, 255], dtype=torch.uint8)
print(ShiftIntensity(offset=1.0, safe=True)(img)) # [1, 101, 255] clamped, as documented
print(ShiftIntensity(offset=1, safe=True)(img)) # [1, 101, 0] wraps despite safe=True
print(ShiftIntensity(offset=-1, safe=True)(img)) # [255, 99, 254] wraps despite safe=True
Expected behavior
With safe=True, an int offset should give the same result as the equivalent float offset: [1, 101, 255] and [0, 99, 254]
Screenshots
If applicable, add screenshots to help explain your problem.
Environment
MONAI 1.6.1rc0+65.gc5bddb21 (dev @ c5bddb21), PyTorch 2.15.0, NumPy 2.4.6, Python 3.11.5, macOS arm64.
Additional context
One possible fix is to compute the shift in a wider dtype (e.g. cast offset to float, or promote img) before the safe conversion. As far as I can tell there's no test covering safe in tests/transforms/test_shift_intensity*.py. I'm happy to open a PR with a fix and a test if this is considered a bug.
Investigation and draft assisted by Claude (AI); I reproduced and verified the behavior myself.
- Lingua principale
- Python
- Stelle
- 8.8k
- Fork
- 1.7k
- Merge medio
- 6g 1h
- PR unite (30g)
- 15
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Project-MONAI/MONAI
-
Small-integer inputs produce incorrect regression metric values or runtime errorsForse già presa @leecoring l’ha presa 4 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Project-MONAI/MONAI#9246 ·
I maintainer di solito rispondono entro 3 giorni
-
partition_datasetForse già presa @rtmalikian l’ha presa 9 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Project-MONAI/MONAI#9220 ·
I maintainer di solito rispondono entro 3 giorni
-
partition_dataset with ratios leaves some items out of every partitionForse già presa @mottopanikeiku l’ha presa 15 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Project-MONAI/MONAI#9216 ·
I maintainer di solito rispondono entro 3 giorni
-
FocalLoss mean reduction is multiplied by the number of channels when ignore_index is setForse già presa @mottopanikeiku l’ha presa 15 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
Project-MONAI/MONAI#9214 ·
I maintainer di solito rispondono entro 3 giorni
-
DiNTS: missing graph-break regression test (follow-up to #9145)Forse già presa @nilapate l’ha presa 28 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
Project-MONAI/MONAI#9159 ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di Project-MONAI/MONAI
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Textualize/textual#6753 · 1 commento ·
-
priority:low size:small
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
RonaldHensbergen/composable-data-stack#1177 ·
I maintainer di solito rispondono entro 1 giorno
-
Use registered media types for HDF5 and NetCDF, and stop claiming media_type must be IANA-registeredApertadocumentation metadata
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
I maintainer di solito rispondono entro 1 giorno
-
check-typing: ty 0.0.98+ fails on the renamed rule `unresolved-import` (now `import-not-found`)Forse già presa @oberstet l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 91/100
crossbario/cfxdb#145 ·