Project-MONAI / MONAI

AI Toolkit for Healthcare Imaging
https://monai.io/
Apache License 2.0
5.86k stars 1.08k forks source link

`reverse_indexing` crashes for `ITKReader` when using `.nrrd` #7372

Open surajpaib opened 10 months ago

surajpaib commented 10 months ago

Describe the bug Setting reverse_indexing=True works well for NIFTI files but crashes for NRRD files when setting reader="ITKReader" in LoadImage

To Reproduce

_Case 1: Load NIFTI without setting reverse_indexing - Works!_

import monai
import matplotlib.pyplot as plt

nrrd_datalist = ["/mnt/data1/RadiomicsFoundationModel/LUNG1/NRRDs/LUNG1-001/CT.nrrd"]
nifti_datalist = ["/mnt/data1/SOTASeg/Dataset600_TotalSegmentator_all_fullres/imagesTr/TotalSegmentator_1405_0000.nii.gz"]

transform = monai.transforms.Compose([
                                      monai.transforms.LoadImage(image_only=True, ensure_channel_first=True, reader="ITKReader"),
                                      monai.transforms.DataStats(),
                                      ])

out = transform(nifti_datalist)

Data statistics: Type: <class 'monai.data.meta_tensor.MetaTensor'> torch.float32 Shape: torch.Size([1, 255, 255, 287]) Value range: (-1179.0, 3262.0)

_Case 2: Load NIFTI setting reverse_indexing=True - Works!_

import monai
import matplotlib.pyplot as plt

nrrd_datalist = ["/mnt/data1/RadiomicsFoundationModel/LUNG1/NRRDs/LUNG1-001/CT.nrrd"]
nifti_datalist = ["/mnt/data1/SOTASeg/Dataset600_TotalSegmentator_all_fullres/imagesTr/TotalSegmentator_1405_0000.nii.gz"]

transform = monai.transforms.Compose([
                                      monai.transforms.LoadImage(image_only=True, ensure_channel_first=True, reader="ITKReader", reverse_indexing=True),
                                      monai.transforms.DataStats(),
                                      ])

out = transform(nifti_datalist)

Data statistics: Type: <class 'monai.data.meta_tensor.MetaTensor'> torch.float32 Shape: torch.Size([1, 287, 255, 255]) Value range: (-1179.0, 3262.0)

_Case 3: Load NRRD without setting reverse_indexing - Works!_

import monai
import matplotlib.pyplot as plt

nrrd_datalist = ["/mnt/data1/RadiomicsFoundationModel/LUNG1/NRRDs/LUNG1-001/CT.nrrd"]
nifti_datalist = ["/mnt/data1/SOTASeg/Dataset600_TotalSegmentator_all_fullres/imagesTr/TotalSegmentator_1405_0000.nii.gz"]

transform = monai.transforms.Compose([
                                      monai.transforms.LoadImage(image_only=True, ensure_channel_first=True, reader="ITKReader"),
                                      monai.transforms.DataStats(),
                                      ])

out = transform(nrrd_datalist)

Data statistics: Type: <class 'monai.data.meta_tensor.MetaTensor'> torch.float32 Shape: torch.Size([1, 512, 512, 134]) Value range: (-1024.0, 3034.0)

_Case 4: Load NRRD setting reverse_indexing=True Breaks_

import monai
import matplotlib.pyplot as plt

nrrd_datalist = ["/mnt/data1/RadiomicsFoundationModel/LUNG1/NRRDs/LUNG1-001/CT.nrrd"]
nifti_datalist = ["/mnt/data1/SOTASeg/Dataset600_TotalSegmentator_all_fullres/imagesTr/TotalSegmentator_1405_0000.nii.gz"]

transform = monai.transforms.Compose([
                                      monai.transforms.LoadImage(image_only=True, ensure_channel_first=True, reader="ITKReader", reverse_indexing=True),
                                      monai.transforms.DataStats(),
                                      ])

out = transform(nrrd_datalist)

Error message: Segmentation fault (core dumped)

Environment monai_env_config.txt

surajpaib commented 10 months ago

Also mentioned in #7365

KumoLiu commented 10 months ago

Hi @surajpaib, can not reproduce the issue, could you please share a case then I can take a look at it? Thanks!