Ejemplo n.º 1
0
def test_register_dwi_series():
    fdata, fbval, fbvec = dpd.get_fnames('small_64D')
    with nbtmp.InTemporaryDirectory() as tmpdir:
        # Use an abbreviated data-set:
        img = nib.load(fdata)
        data = img.get_fdata()[..., :10]
        nib.save(nib.Nifti1Image(data, img.affine),
                 op.join(tmpdir, 'data.nii.gz'))
        # Save a subset:
        bvals = np.loadtxt(fbval)
        bvecs = np.loadtxt(fbvec)
        np.savetxt(op.join(tmpdir, 'bvals.txt'), bvals[:10])
        np.savetxt(op.join(tmpdir, 'bvecs.txt'), bvecs[:10])
        gtab = dpg.gradient_table(op.join(tmpdir, 'bvals.txt'),
                                  op.join(tmpdir, 'bvecs.txt'))
        reg_img, reg_affines = register_dwi_series(data, gtab, img.affine)
        npt.assert_(isinstance(reg_img, nib.Nifti1Image))
Ejemplo n.º 2
0
def diff_data_registration(data, affine, bvec, bval, big_delta, small_delta, b0_ref=0):
    from dipy.align import register_dwi_series
    from dipy.core.gradients import gradient_table
    from scipy.ndimage import gaussian_filter

    gtab = gradient_table(bval, bvec, big_delta=big_delta, small_delta=small_delta)
    nbvec = np.zeros(np.shape(bvec))


    rdata, tform = register_dwi_series(data, gtab=gtab, affine=affine, b0_ref = b0_ref)
    rd = rdata.get_fdata()
    rdata_smooth = np.zeros(np.shape(rd))
    for i in range(0,len(bval)):
        nbvec[i,:] = np.dot(bvec[i,:],tform[:,:,i].transpose()[:3,:3])
        rdata_smooth[:,:,:,i] = gaussian_filter(rd[:,:,:,i],sigma=0.65,truncate=7)


    return rdata_smooth, tform, nbvec