From 59df6f470fc044836d2f98011dab6dd55fc185d4 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Fri, 28 Apr 2023 11:59:06 +0200 Subject: [PATCH 1/2] fix: set x-forms on resampled images Resolves: #175. --- nitransforms/base.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/nitransforms/base.py b/nitransforms/base.py index 9a1600a0..ce69ddbc 100644 --- a/nitransforms/base.py +++ b/nitransforms/base.py @@ -11,6 +11,7 @@ import numpy as np import h5py import warnings +from collections import namedtuple from nibabel.loadsave import load as _nbload from nibabel import funcs as _nbfuncs from nibabel.nifti1 import intent_codes as INTENT_CODES @@ -92,7 +93,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.""" @@ -101,6 +102,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: @@ -117,6 +119,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.""" @@ -293,12 +300,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 From 2c5a44e7db75fa5c1941bf05f43f9dddcf84a159 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Tue, 13 Jun 2023 11:33:23 +0200 Subject: [PATCH 2/2] sty: remove unused import --- nitransforms/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nitransforms/base.py b/nitransforms/base.py index ce69ddbc..25fd88e0 100644 --- a/nitransforms/base.py +++ b/nitransforms/base.py @@ -11,7 +11,6 @@ import numpy as np import h5py import warnings -from collections import namedtuple from nibabel.loadsave import load as _nbload from nibabel import funcs as _nbfuncs from nibabel.nifti1 import intent_codes as INTENT_CODES