Skip to content

Spacing transform does not update pixdim #6832

Description

@KumoLiu

Discussed in #6831

Originally posted by agaldran August 7, 2023
Hello,

Sorry about the naive question, I am trying to wrap my head around transforms and meta_dicts. Right now I have the following operations:

import monai.transforms as t

data_dict = {'image': 'data/ct/images/.whatever.nii.gz'}
loader = t.LoadImaged(keys=('image'), image_only=False)
loaded_data_dict = loader(data_dict)
print(loaded_data_dict['image'].shape, loaded_data_dict['image_meta_dict']['pixdim'][1:4])

which returns a shape and voxel sizes of [281, 313, 182] and (0.50,0.50,0.75) respectively. Now, if I run:

spacing = t.Spacingd(keys=['image'], pixdim=(0.50, 0.50, 1.5), mode=('bilinear')) 
spaced_data_dict = spacing(loaded_data_dict)
print(spaced_data_dict['image'].shape, spaced_data_dict['image_meta_dict']['pixdim'][1:4])

I am expecting to see approx half the voxels in the Z direction, as the original spacing was 0.75 and I am asking for twice that spacing. For the other directions, nothing should be changed^* . This is what I get:

[281, 313, 92], (0.50,0.50,0.75)

So, although the number of voxels are as expected, the spacing remains the same. I cannot find any other key in the meta data dictionary that tells me what is the current spacing for this volume. Am I doing something wrong here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions