Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Set x-forms on resampled images #176

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions nitransforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def shape(self):
class ImageGrid(SampledSpatialData):
"""Class to represent spaces of gridded data (images)."""

__slots__ = ["_affine", "_inverse", "_ndindex"]
__slots__ = ["_affine", "_inverse", "_ndindex", "_header"]

def __init__(self, image):
"""Create a gridded sampling reference."""
Expand All @@ -101,6 +101,7 @@ def __init__(self, image):

self._affine = image.affine
self._shape = image.shape
self._header = getattr(image, "header", None)

self._ndim = getattr(image, "ndim", len(image.shape))
if self._ndim >= 4:
Expand All @@ -117,6 +118,11 @@ def affine(self):
"""Access the indexes-to-RAS affine."""
return self._affine

@property
def header(self):
"""Access the original reference's header."""
return self._header

@property
def inverse(self):
"""Access the RAS-to-indexes affine."""
Expand Down Expand Up @@ -293,12 +299,15 @@ def apply(
)

if isinstance(_ref, ImageGrid): # If reference is grid, reshape
hdr = None
if _ref.header is not None:
hdr = _ref.header.copy()
hdr.set_data_dtype(output_dtype)
moved = spatialimage.__class__(
resampled.reshape(_ref.shape).astype(output_dtype),
_ref.affine,
spatialimage.header
hdr,
)
moved.set_data_dtype(output_dtype)
return moved

return resampled
Expand Down