Skip to content

Niftisaver doesn't save new voxelspacing #3307

Description

@wyli

Discussed in #3299 as well as #2029

Originally posted by Gijz33 November 10, 2021
Hi,

I am changing the voxel spacing of my CT data using monai.transforms.Spacingd and saving the CT with new spacing into a .nii.gz-file using monai.data.NiftiSaver.
The voxel size transformation is succesful inside the python script. However, opening the .nii.gz file using different software (3D-slicer) the spacing of the old/orginal CT is used. Can someone help me out? A snippet of my code is shown below:

train_images = sorted(glob.glob(os.path.join(data_folder, "*_ct.nii.gz")))
train_labels = sorted(glob.glob(os.path.join(data_folder, "*_seg.nii.gz")))

data_dicts = [    {"image": image_name, "label": label_name} for image_name, label_name in zip(train_images, train_labels)    ]

loader = LoadImaged(keys=("image","label"))
data_dict = loader(data_dicts[0])
     
add_channel = AddChanneld(keys=["image", "label"])
data_dict = add_channel(data_dict)

orientation = Orientationd(keys=["image", "label"], axcodes="LPS")
data_dict = orientation(data_dict)

spacing = Spacingd(keys=["image", "label"], pixdim=(0.8, 0.8, 3.0), mode=("bilinear")) 
data_dict = spacing(data_dict)


saver = NiftiSaver(output_dir="./", output_postfix="test" ,output_ext=".nii.gz",mode="nearest")
saver.save(data_dict["image"], data_dict['image_meta_dict'])

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    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