Project-MONAI / MONAI

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

MONAI loading a NRRD file into wrong orientation #3356

Closed mattwarkentin closed 3 years ago

mattwarkentin commented 3 years ago

Describe the bug When I load a NRRD file, the array is not in the right orientation according to the affine. Here is the text header of the NRRD file.

NRRD0004
# Complete NRRD file format specification at:
# http://teem.sourceforge.net/nrrd/format.html
type: short
dimension: 3
space: left-posterior-superior
sizes: 512 512 321
space directions: (0.767578125,0,0) (0,0.767578125,0) (0,0,1)
kinds: domain domain domain
endian: little
encoding: raw
space origin: (-197.1162109375,-371.1162109375,-403)

To Reproduce

import monai

sub = {'img': 'image.nrrd'}

sub = monai.transforms.LoadImaged('img')(sub)

sub['img'].shape
# (321, 512, 512)

sub['img_meta_dict']['affine']
# array([[   0.76757812,    0.        ,    0.        , -197.11621094],
#        [   0.        ,    0.76757812,    0.        , -371.11621094],
#        [   0.        ,    0.        ,    1.        , -403.        ],
#        [   0.        ,    0.        ,    0.        ,    1.        ]])

Expected behavior The array to be the shape of (512, 512, 321) to match the affine.

Environment

Printing MONAI config...

MONAI version: 0.4.0 Numpy version: 1.19.5 Pytorch version: 1.8.1 MONAI flags: HAS_EXT = False, USE_COMPILED = False MONAI rev id: 0563a4467fa602feca92d91c7f47261868d171a1

Optional dependencies: Pytorch Ignite version: 0.4.2 Nibabel version: 3.2.1 scikit-image version: 0.18.2 Pillow version: 8.2.0 Tensorboard version: 2.7.0 gdown version: 4.2.0 TorchVision version: 0.9.1 ITK version: 5.2.1 tqdm version: 4.61.0 lmdb version: NOT INSTALLED or UNKNOWN VERSION. psutil version: 5.8.0

For details about installing the optional dependencies, please visit: https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies

================================ Printing system config...

System: Darwin Mac version: 10.16 Platform: Darwin-20.6.0-x86_64-i386-64bit Processor: i386 Machine: x86_64 Python version: 3.7.10 Process name: Python Command: ['/usr/local/Cellar/python@3.7/3.7.10_3/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python', '-c', 'import monai; monai.config.print_debug_info()'] Open files: [] Num physical CPUs: 6 Num logical CPUs: 12 Num usable CPUs: UNKNOWN for given OS CPU usage (%): [14.6, 8.2, 50.0, 6.2, 10.4, 8.2, 8.3, 8.2, 37.5, 8.2, 26.5, 6.2] CPU freq. (MHz): 3200 Load avg. in last 1, 5, 15 mins (%): [19.0, 18.5, 17.4] Disk usage (%): 38.2 Avg. sensor temp. (Celsius): UNKNOWN for given OS Total physical memory (GB): 64.0 Available memory (GB): 42.7 Used memory (GB): 20.2

================================ Printing GPU config...

Num GPUs: 0 Has CUDA: False cuDNN enabled: False

mattwarkentin commented 3 years ago

Looks like I accidentally downgraded to an old version of MONAI, fixed with upgrade to 0.7.0.