Skip to content

Unused 'affine' argument in Spacing transform #4791

@amissert

Description

@amissert

Describe the bug
The Spacing transform accepts an affine argument, but the argument is unused by the __call__ function and has no effect on the output.

To Reproduce

from monai import transforms as trans
from monai.data.meta_tensor import MetaTensor

def test_monai_utils():

    # fake data
    x = np.ones((1, 64, 64, 64))

    # fake affines
    affine_1 = np.eye(4)
    affine_2 = np.eye(4) * 2

    resamp = trans.Spacing(pixdim=[1, 1, 1], diagonal=False, mode='bilinear')

    # using MetaTensor works as expected
    y_1 = resamp(MetaTensor(x, affine=affine_1))
    y_2 = resamp(MetaTensor(x, affine=affine_2))
    assert not all(i == j for i, j in zip(y_1.shape, y_2.shape))

    # using affine has no effect
    y_1 = resamp(x, affine=affine_1)
    y_2 = resamp(x, affine=affine_2)

    # these shapes should be different!
    assert not all(i == j for i, j in zip(y_1.shape, y_2.shape))

Expected behavior
Either have the affine argument override the input data_array.affine, or remove the affine argument altogether in favor of data_array.affine.

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