Skip to content

Commit

Permalink
Merge pull request #115 from Parietal-INRIA/fix/3d-4d-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
pbarbarant authored Dec 10, 2024
2 parents 077501e + 0031a2b commit a629598
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fmralign/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ def _fit_masker(self, imgs):

if isinstance(imgs, Nifti1Image):
imgs = [imgs]
# If images are 3D, add a fourth dimension
for i, img in enumerate(imgs):
if len(img.shape) == 3:
imgs[i] = Nifti1Image(
np.expand_dims(img.get_fdata(), axis=-1),
img.affine,
img.header,
)
# Assert that all images have the same shape
if len(set([img.shape for img in imgs])) > 1:
raise NotImplementedError(
Expand Down
10 changes: 10 additions & 0 deletions fmralign/tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ def test_standardization():
assert np.abs(np.std(data_array) - 1.0) < 1e-5


def test_one_contrast():
"""Test that ParcellationMasker handles both 3D and\n
4D images in the case of one contrast"""
img1, _ = random_niimg((8, 7, 6))
img2, _ = random_niimg((8, 7, 6, 1))
pmasker = ParcellationMasker()
pmasker.fit([img1, img2])


def test_get_parcellation():
"""Test that ParcellationMasker returns the parcellation mask"""
n_pieces = 2
Expand All @@ -198,3 +207,4 @@ def test_get_parcellation():

assert np.allclose(data, labels)
assert len(np.unique(data)) == n_pieces

0 comments on commit a629598

Please sign in to comment.