Skip to content

Spacing transforms scale pixel dimensions or resample to specified pixel dimensions #2304

@shawnfan19

Description

@shawnfan19

Hello!

Is the Spacing transform meant to resample a given volume to a specified the pixel dimensions? I have NiFTI images with different voxel dimensions and am trying to resample all of them to (2mm, 2mm, 2mm) using the following code. \

fpaths = ["img0.nii", "img1.nii"]
transform = Compose([
        AsChannelFirst(channel_dim=-1),
        Spacing(pixdim=(2, 2, 2), mode="bilinear", diagonal=True),
        ScaleIntensity(minv=0.0, maxv=1.0),
        ToTensor(),
    ])
check_ds = ImageDataset(image_files=fpaths, transform=transform)

for i, img in enumerate(check_ds):

    print(check_ds[i][0].shape)

img0.nii has a pixel size of (2mm, 2mm, 2mm) to begin with so it should remain unchanged by the transform, but its dimensions were shrunk by a factor of 2 from (128, 128, 90) to (64, 64, 46) img1.nii has a pixel size of (2mm, 2mm, 3.27mm), its first two dimensions should remain unchanged whereas the third dimension should expand to account for the reduced pixel size. However, its dimensions were reduced from (128, 128, 47) to (64, 64, 24). It appears that the Spacing transform only scales the pixel dimensions by a factor of 2 instead of resampling them to the specified dimensions. Is this the normal behavior?

I am using Mona 0.5.2 and you can find the aforementioned NiFTI files here (https://drive.google.com/drive/folders/1k__dds_31elP-zkelCNSguWIDrHPTDe5?usp=sharing)

Thank you for looking into this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions