Version: brainles_preprocessing 0.6.13 (same in 0.6.10)
ANTsRegistrator.transform defaults to interpolator="nearestNeighbor", and ANTsRegistrator.register calls self.transform(...) without passing an interpolator. Modality.register / Modality.transform also never pass one (brainles_preprocessing/modality.py:265, :398, :411).
As a result, every resampling step in AtlasCentricPreprocessor.run (coregistration to the center modality, atlas registration incl. the combined coregistration+atlas transform, atlas correction) resamples the MRI modalities with nearest neighbor.
There currently seems to be no supported way to change this from the user side: passing ANTsRegistrator(transformation_params={"interpolator":"linear"}) fails with "TypeError: apply_transforms() got multiple values for keyword argument 'interpolator'" because transform forwards interpolator=interpolator, **transform_kwargs to ants.apply_transforms (ANTs.py:217). The only workaround is subclassing ANTsRegistrator and overriding the default of transform.
Suggested fix: default interpolator to "linear" in ANTsRegistrator.transform (and inverse_transform), and let Modality.register / Modality.transform pass an interpolator.
Reproducibility
import tempfile
from pathlib import Path
import ants
import numpy as np
from brainles_preprocessing.registration import ANTsRegistrator
tmp = Path(tempfile.mkdtemp())
img = tmp / "img.nii.gz"
ants.image_write(ants.from_numpy(np.random.rand(16, 16, 16).astype(np.float32)), str(img))
tx = tmp / "identity.mat"
ants.write_transform(ants.new_ants_transform(dimension=3, transform_type="AffineTransform"), str(tx))
registrator = ANTsRegistrator(transformation_params={"interpolator": "linear"})
registrator.transform(
fixed_image_path=img,
moving_image_path=img,
transformed_image_path=tmp / "out.nii.gz",
matrix_path=tx,
log_file_path=tmp / "log.txt",
)
Version: brainles_preprocessing 0.6.13 (same in 0.6.10)
ANTsRegistrator.transform defaults to interpolator="nearestNeighbor", and ANTsRegistrator.register calls self.transform(...) without passing an interpolator. Modality.register / Modality.transform also never pass one (brainles_preprocessing/modality.py:265, :398, :411).
As a result, every resampling step in AtlasCentricPreprocessor.run (coregistration to the center modality, atlas registration incl. the combined coregistration+atlas transform, atlas correction) resamples the MRI modalities with nearest neighbor.
There currently seems to be no supported way to change this from the user side: passing ANTsRegistrator(transformation_params={"interpolator":"linear"}) fails with "TypeError: apply_transforms() got multiple values for keyword argument 'interpolator'" because transform forwards interpolator=interpolator, **transform_kwargs to ants.apply_transforms (ANTs.py:217). The only workaround is subclassing ANTsRegistrator and overriding the default of transform.
Suggested fix: default interpolator to "linear" in ANTsRegistrator.transform (and inverse_transform), and let Modality.register / Modality.transform pass an interpolator.
Reproducibility
import tempfile
from pathlib import Path
import ants
import numpy as np
from brainles_preprocessing.registration import ANTsRegistrator
tmp = Path(tempfile.mkdtemp())
img = tmp / "img.nii.gz"
ants.image_write(ants.from_numpy(np.random.rand(16, 16, 16).astype(np.float32)), str(img))
tx = tmp / "identity.mat"
ants.write_transform(ants.new_ants_transform(dimension=3, transform_type="AffineTransform"), str(tx))
registrator = ANTsRegistrator(transformation_params={"interpolator": "linear"})
registrator.transform(
fixed_image_path=img,
moving_image_path=img,
transformed_image_path=tmp / "out.nii.gz",
matrix_path=tx,
log_file_path=tmp / "log.txt",
)