ShiftIntensity(safe=True) still wraps uint8 values when `offset` is an int
Los mantenedores suelen responder en 3 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 84/100
Línea de trabajo
Lee ShiftIntensity.__call__ en monai/transforms/intensity/array.py y las pruebas de tests/transforms/test_shift_intensity*.py. Reproduce el caso informado con uint8 y desplazamientos enteros y de coma flotante. Después, añade cobertura para safe=True y las transformaciones Random o Dictionary relacionadas si resulta sencillo hacerlo con las pruebas existentes. El trabajo estará terminado cuando los desplazamientos enteros produzcan los valores limitados esperados y pasen las pruebas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
[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.
- Lenguaje dominante
- Python
- Estrellas
- 8.8k
- Forks
- 1.7k
- Merge medio
- 6 d 1 h
- PR fusionados (30 d)
- 15
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Project-MONAI/MONAI
-
Small-integer inputs produce incorrect regression metric values or runtime errorsPosiblemente ocupada @leecoring la tomó hace 4 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Project-MONAI/MONAI#9246 ·
Los mantenedores suelen responder en 3 días
-
partition_datasetPosiblemente ocupada @rtmalikian la tomó hace 9 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Project-MONAI/MONAI#9220 ·
Los mantenedores suelen responder en 3 días
-
partition_dataset with ratios leaves some items out of every partitionPosiblemente ocupada @mottopanikeiku la tomó hace 14 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Project-MONAI/MONAI#9216 ·
Los mantenedores suelen responder en 3 días
-
FocalLoss mean reduction is multiplied by the number of channels when ignore_index is setPosiblemente ocupada @mottopanikeiku la tomó hace 14 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Project-MONAI/MONAI#9214 ·
Los mantenedores suelen responder en 3 días
-
DiNTS: missing graph-break regression test (follow-up to #9145)Posiblemente ocupada @nilapate la tomó hace 28 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Project-MONAI/MONAI#9159 ·
Los mantenedores suelen responder en 3 días
Todos los issues de Project-MONAI/MONAI
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
didi/helixharness#18 ·
-
[MOVIE]: Airport '77 (1977)Abiertorequest-theme
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
LizardByte/ThemerrDB#9883 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
NousResearch/hermes-agent#149885 ·
Los mantenedores suelen responder en 1 día
-
Set cache_ok = True on GUID TypeDecorator to enable SQLAlchemy query cachingPosiblemente ocupada @patelshivani2283-lab la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
fedora-infra/anitya#2157 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
mllam/neural-lam#860 ·
Los mantenedores suelen responder en 2 días