ShiftIntensity(safe=True) still wraps uint8 values when `offset` is an int
Mantenedores costumam responder em até 3 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 84/100
Direção de pesquisa
Leia ShiftIntensity.__call__ em monai/transforms/intensity/array.py e os testes em tests/transforms/test_shift_intensity*.py. Reproduza o caso relatado com uint8 e deslocamentos inteiros e de ponto flutuante. Em seguida, adicione testes para safe=True e para as transformações Random ou Dictionary relacionadas, se isso for simples com os testes existentes. O trabalho estará concluído quando os deslocamentos inteiros produzirem os valores limitados esperados e os testes passarem.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
[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.
- Linguagem predominante
- Python
- Estrelas
- 8.8k
- Forks
- 1.7k
- Merge médio
- 6d 1h
- PRs com merge (30d)
- 15
Preparar o ambiente
- Inclui um Dockerfile ou arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de Project-MONAI/MONAI
-
Small-integer inputs produce incorrect regression metric values or runtime errorsTalvez já em andamento @leecoring assumiu há 4 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Project-MONAI/MONAI#9246 ·
Mantenedores costumam responder em até 3 dias
-
partition_datasetTalvez já em andamento @rtmalikian assumiu há 9 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Project-MONAI/MONAI#9220 ·
Mantenedores costumam responder em até 3 dias
-
partition_dataset with ratios leaves some items out of every partitionTalvez já em andamento @mottopanikeiku assumiu há 14 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Project-MONAI/MONAI#9216 ·
Mantenedores costumam responder em até 3 dias
-
FocalLoss mean reduction is multiplied by the number of channels when ignore_index is setTalvez já em andamento @mottopanikeiku assumiu há 14 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Project-MONAI/MONAI#9214 ·
Mantenedores costumam responder em até 3 dias
-
DiNTS: missing graph-break regression test (follow-up to #9145)Talvez já em andamento @nilapate assumiu há 28 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
Project-MONAI/MONAI#9159 ·
Mantenedores costumam responder em até 3 dias
Todas as issues de Project-MONAI/MONAI
Issues semelhantes
-
area/test type/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Clodmony/starship-coop#70 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
punitarani/fli#270 ·
-
🐛 Bug 🔔 Pending processing
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
jumpserver/jumpserver#17980 ·
Mantenedores costumam responder em até 1 dia
-
community enhancement good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
Mantenedores costumam responder em até 1 dia
-
namespace
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 60/100
EclipseFdn/open-vsx.org#15341 ·
Mantenedores costumam responder em até 1 dia