Beispiel #1
0
def _check_vol_to_surf_results(img, mesh):
    mni_mask = datasets.load_mni152_brain_mask()
    for kind, interpolation, mask_img in itertools.product(
        ['ball', 'line'], ['linear', 'nearest'], [mni_mask, None]):
        proj_1 = vol_to_surf(img,
                             mesh,
                             kind=kind,
                             interpolation=interpolation,
                             mask_img=mask_img)
        assert_true(proj_1.ndim == 1)
        img_rot = image.resample_img(img,
                                     target_affine=rotation(
                                         np.pi / 3., np.pi / 4.))
        proj_2 = vol_to_surf(img_rot,
                             mesh,
                             kind=kind,
                             interpolation=interpolation,
                             mask_img=mask_img)
        # The projection values for the rotated image should be close
        # to the projection for the original image
        diff = np.abs(proj_1 - proj_2) / np.abs(proj_1)
        assert_true(np.mean(diff[diff < np.inf]) < .03)
        img_4d = image.concat_imgs([img, img])
        proj_4d = vol_to_surf(img_4d,
                              mesh,
                              kind=kind,
                              interpolation=interpolation,
                              mask_img=mask_img)
        nodes, _ = surface.load_surf_mesh(mesh)
        assert_array_equal(proj_4d.shape, [nodes.shape[0], 2])
        assert_array_almost_equal(proj_4d[:, 0], proj_1, 3)
Beispiel #2
0
def test_vol_to_surf(kind, n_scans, use_mask):
    img, mask_img = data_gen.generate_mni_space_img(n_scans)
    if not use_mask:
        mask_img = None
    if n_scans == 1:
        img = image.new_img_like(img, image.get_data(img).squeeze())
    fsaverage = datasets.fetch_surf_fsaverage()
    mesh = surface.load_surf_mesh(fsaverage["pial_left"])
    inner_mesh = surface.load_surf_mesh(fsaverage["white_left"])
    center_mesh = np.mean([mesh[0], inner_mesh[0]], axis=0), mesh[1]
    proj = surface.vol_to_surf(
        img, mesh, kind="depth", inner_mesh=inner_mesh, mask_img=mask_img)
    other_proj = surface.vol_to_surf(
        img, center_mesh, kind=kind, mask_img=mask_img)
    correlation = pearsonr(proj.ravel(), other_proj.ravel())[0]
    assert correlation > .99
    with pytest.raises(ValueError, match=".*interpolation.*"):
        surface.vol_to_surf(img, mesh, interpolation="bad")
Beispiel #3
0
def test_check_mesh():
    mesh = surface._check_mesh('fsaverage5')
    assert mesh is surface._check_mesh(mesh)
    with pytest.raises(ValueError):
        surface._check_mesh('fsaverage2')
    mesh.pop('pial_left')
    with pytest.raises(ValueError):
        surface._check_mesh(mesh)
    with pytest.raises(TypeError):
        surface._check_mesh(surface.load_surf_mesh(mesh['pial_right']))
Beispiel #4
0
def _check_vol_to_surf_results(img, mesh):
    mni_mask = datasets.load_mni152_brain_mask()
    for kind, interpolation, mask_img in itertools.product(
            ['ball', 'line'], ['linear', 'nearest'], [mni_mask, None]):
        proj_1 = vol_to_surf(
            img, mesh, kind=kind, interpolation=interpolation,
            mask_img=mask_img)
        assert_true(proj_1.ndim == 1)
        img_rot = image.resample_img(
            img, target_affine=rotation(np.pi / 3., np.pi / 4.))
        proj_2 = vol_to_surf(
            img_rot, mesh, kind=kind, interpolation=interpolation,
            mask_img=mask_img)
        # The projection values for the rotated image should be close
        # to the projection for the original image
        diff = np.abs(proj_1 - proj_2) / np.abs(proj_1)
        assert_true(np.mean(diff[diff < np.inf]) < .03)
        img_4d = image.concat_imgs([img, img])
        proj_4d = vol_to_surf(
            img_4d, mesh, kind=kind, interpolation=interpolation,
            mask_img=mask_img)
        nodes, _ = surface.load_surf_mesh(mesh)
        assert_array_equal(proj_4d.shape, [nodes.shape[0], 2])
        assert_array_almost_equal(proj_4d[:, 0], proj_1, 3)
Beispiel #5
0
def test_depth_ball_sampling():
    img, *_ = data_gen.generate_mni_space_img()
    mesh = surface.load_surf_mesh(datasets.fetch_surf_fsaverage()["pial_left"])
    with pytest.raises(ValueError, match=".*does not support.*"):
        surface.vol_to_surf(img, mesh, kind="ball", depth=[.5])