Skip to content

Commit

Permalink
Merge branch 'main' into feat/one-parcellation-template
Browse files Browse the repository at this point in the history
  • Loading branch information
pbarbarant authored Dec 10, 2024
2 parents e55d982 + a629598 commit a413c75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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
12 changes: 11 additions & 1 deletion fmralign/tests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,16 @@ def test_standardization():
assert np.abs(np.std(data_array) - 1.0) < 1e-5


def test_get_parcellatio_img():
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_img():
"""Test that ParcellationMasker returns the parcellation mask"""
n_pieces = 2
img, _ = random_niimg((8, 7, 6))
Expand All @@ -198,3 +207,4 @@ def test_get_parcellatio_img():

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

0 comments on commit a413c75

Please sign in to comment.