When using lazy transform, specifying an interpolation method still applies the default bilinear interpolation to the image. For instance, when resizing an image mask with nearest neighbors interpolation, the mode is reset to None (defaulting to bilinear), leading to an incorrect mask.
from monai.transforms import (
Compose,
Resized
)
import numpy as np
def generateTransform(image_size = (15, 15, 15)):
return Compose(
[
Resized(
keys=["image", "label"],
spatial_size=image_size,
mode=("bilinear", "nearest"),
),
],
lazy=True,
)
image = np.random.rand(10, 10, 10)
mask = np.random.randint(0, 2, size=(10, 10, 10))
print(np.unique(mask))
#[0 1]
data_dict = {'image': image, 'label': mask}
sample = generateTransform()(data_dict)
print(np.unique(sample['label']))
#[0. 0.02777778 0.08333334 0.1388889 0.16666667 0.25 0.2777778 0.30555555 0.41666666 0.5 ...]
Expected behavior
The interpolation method applied to the mask should be nearest neighbours. The method defaults to bilinear, giving us a mask with float values. It seems the interpolation mode is not passed through the composed transforms when using the lazy flag.
Environment
Python 3.10.12.
monai 1.3
numpy 1.24.4
When using lazy transform, specifying an interpolation method still applies the default bilinear interpolation to the image. For instance, when resizing an image mask with nearest neighbors interpolation, the mode is reset to None (defaulting to bilinear), leading to an incorrect mask.
Expected behavior
The interpolation method applied to the mask should be nearest neighbours. The method defaults to bilinear, giving us a mask with float values. It seems the interpolation mode is not passed through the composed transforms when using the lazy flag.
Environment
Python 3.10.12.
monai 1.3
numpy 1.24.4