def test_inverse_transform_single_nifti_image(): data = np.ones((10, 11, 12, 10)) data[6, 7, 8] = 2 data[9, 10, 11] = 3 fmri_img = nibabel.Nifti1Image(data, affine=np.eye(4)) methods = ['kmeans', 'ward', 'complete', 'average', 'rena'] for method in methods: parcellate = Parcellations(method=method, n_parcels=5) # Fit parcellate.fit(fmri_img) assert parcellate.labels_img_ is not None # Transform fmri_reduced = parcellate.transform(fmri_img) assert isinstance(fmri_reduced, np.ndarray) # Shape matching with (scans, regions) assert fmri_reduced.shape, (10, 5) # Inverse transform fmri_compressed = parcellate.inverse_transform(fmri_reduced) # A single Nifti image for single subject input assert isinstance(fmri_compressed, nibabel.Nifti1Image) # returns shape of fmri_img assert fmri_compressed.shape, (10, 11, 12, 10) # fmri_reduced in a list fmri_compressed = parcellate.inverse_transform([fmri_reduced]) # A single Nifti image for single subject input assert isinstance(fmri_compressed, nibabel.Nifti1Image) # returns shape of fmri_img assert fmri_compressed.shape, (10, 11, 12, 10)
def test_inverse_transform_single_nifti_image(): data = np.ones((10, 11, 12, 10)) data[6, 7, 8] = 2 data[9, 10, 11] = 3 fmri_img = nibabel.Nifti1Image(data, affine=np.eye(4)) methods = ['kmeans', 'ward', 'complete', 'average'] for method in methods: parcellate = Parcellations(method=method, n_parcels=5) # Fit parcellate.fit(fmri_img) assert_true(parcellate.labels_img_ is not None) # Transform fmri_reduced = parcellate.transform(fmri_img) assert_true(isinstance(fmri_reduced, np.ndarray)) # Shape matching with (scans, regions) assert_true(fmri_reduced.shape, (10, 5)) # Inverse transform fmri_compressed = parcellate.inverse_transform(fmri_reduced) # A single Nifti image for single subject input assert_true(isinstance(fmri_compressed, nibabel.Nifti1Image)) # returns shape of fmri_img assert_true(fmri_compressed.shape, (10, 11, 12, 10)) # fmri_reduced in a list fmri_compressed = parcellate.inverse_transform([fmri_reduced]) # A single Nifti image for single subject input assert_true(isinstance(fmri_compressed, nibabel.Nifti1Image)) # returns shape of fmri_img assert_true(fmri_compressed.shape, (10, 11, 12, 10))
def test_inverse_transform_single_nifti_image(method, n_parcel, test_image_2): parcellate = Parcellations(method=method, n_parcels=n_parcel) parcellate.fit(test_image_2) assert parcellate.labels_img_ is not None fmri_reduced = parcellate.transform(test_image_2) assert isinstance(fmri_reduced, np.ndarray) # Shape matching with (scans, regions) assert fmri_reduced.shape == (10, n_parcel) fmri_compressed = parcellate.inverse_transform(fmri_reduced) # A single Nifti image for single subject input assert isinstance(fmri_compressed, nibabel.Nifti1Image) # returns shape of fmri_img assert fmri_compressed.shape == test_image_2.shape # fmri_reduced in a list fmri_compressed = parcellate.inverse_transform([fmri_reduced]) # A single Nifti image for single subject input assert isinstance(fmri_compressed, nibabel.Nifti1Image) # returns shape of fmri_img assert fmri_compressed.shape == test_image_2.shape
def test_transform_3d_input_images(): # test list of 3D images data = np.ones((10, 11, 12)) data[6, 7, 8] = 2 data[9, 10, 11] = 3 img = nibabel.Nifti1Image(data, affine=np.eye(4)) imgs = [img] * 3 parcellate = Parcellations(method='ward', n_parcels=20) X = parcellate.fit_transform(imgs) assert isinstance(X, list) # (number of samples, number of features) assert np.concatenate(X).shape == (3, 20) # inverse transform imgs_ = parcellate.inverse_transform(X) assert isinstance(imgs_, list) # test single 3D image X = parcellate.fit_transform(imgs[0]) assert isinstance(X, np.ndarray) assert X.shape == (1, 20)
def test_transform_3d_input_images(): # test list of 3D images data = np.ones((10, 11, 12)) data[6, 7, 8] = 2 data[9, 10, 11] = 3 img = nibabel.Nifti1Image(data, affine=np.eye(4)) # list of 3 imgs = [img, img, img] parcellate = Parcellations(method='ward', n_parcels=20) X = parcellate.fit_transform(imgs) assert_true(isinstance(X, list)) # (number of samples, number of features) assert_equal(np.concatenate(X).shape, (3, 20)) # inverse transform imgs_ = parcellate.inverse_transform(X) assert_true(isinstance(imgs_, list)) # test single 3D image X = parcellate.fit_transform(imgs[0]) assert_true(isinstance(X, np.ndarray)) assert_equal(X.shape, (1, 20))