Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
michalhg opened this issue Nov 20, 2024 · 1 comment

Comments

@michalhg
Copy link

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.

@KumoLiu
Copy link
Contributor

KumoLiu commented Nov 21, 2024

Hi @michalhg, thanks for your interest here.

Yes, this behavior is expected. In MONAI, all transforms (except for the loader) assume that the input data follows the shape [channel x spatial_dims]. This is also explicitly mentioned in the docstring for clarity.

data_array: in shape (num_channels, H[, W, ...]).

@Project-MONAI Project-MONAI locked and limited conversation to collaborators Nov 21, 2024
@KumoLiu KumoLiu converted this issue into discussion #8228 Nov 21, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants