Skip to content

Spacingd generates an error in the new affine matrix when loaded image is not channel first  #8221

@michalhg

Description

@michalhg

when using Spacingd on an image_key than has not been loaded with channel first dimension, the scaling anf the affine matrix generated is incorrect.
LoadImaged(keys=[image_key]),
Spacingd(keys=[image_key], pixdim=(0.7, 0.7, 0.4), mode='bilinear',align_corners=True),

values of affine matrix after loadimage:
Image shape: torch.Size([512, 512, 1019])
Current affine:
[[-3.4582e-01, 0.0000e+00, 0.0000e+00, 5.3887e+01],
[ 0.0000e+00, -3.4582e-01, 0.0000e+00, 2.5348e+02],
[ 0.0000e+00, 0.0000e+00, 2.0000e-01, -1.2827e+03],
[ 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00]],

after resampling:
Image shape: torch.Size([512, 253, 504])
Current affine:
[[-7.0000e-01, 0.0000e+00, 0.0000e+00, 5.3887e+01],
[ 0.0000e+00, -7.0000e-01, 0.0000e+00, 2.5348e+02],
[ 0.0000e+00, 0.0000e+00, 2.0000e-01, -1.2827e+03],
[ 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00]],

However, if I use

LoadImaged(keys=[image_key],ensure_channel_first=True),
resulting affine is correct as is the size.
Image shape: torch.Size([1, 253, 253, 510])
Current affine:
[[-7.0000e-01, 0.0000e+00, 0.0000e+00, 5.3887e+01],
[ 0.0000e+00, -7.0000e-01, 0.0000e+00, 2.5348e+02],
[ 0.0000e+00, 0.0000e+00, 4.0000e-01, -1.2827e+03],
[ 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00]],

Please fix this issue, or give a warning in case the expected format of channel first is not given by the user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions