예제 #1
0
def add_random_rigid_transforms(dwi, grid2world):
    from dipy.align.transforms import RigidTransform3D
    from dipy.align.vector_fields import warp_3d_affine
    if grid2world is None:
        grid2world = np.eye(4)
        world2grid = np.eye(4)
    else:
        world2grid = np.linalg.inv(grid2world)

    # sigmas in degrees
    sigmas = np.array([3, 3, 3, 2, 2, 2], dtype=np.float64)
    # to radians
    sigmas[:3] *= np.pi/180.0
    n = dwi.shape[3]
    rigid = RigidTransform3D()
    transforms = []
    jitter = np.empty_like(dwi)
    for i in range(n):
        theta = np.random.randn(6)
        theta *= sigmas
        gt = rigid.param_to_matrix(theta)
        gt_inv = np.linalg.inv(gt)
        M = world2grid.dot(gt_inv.dot(grid2world))
        in_vol = dwi[...,i].astype(np.float32)
        out_shape = np.array(dwi[...,i].shape, dtype=np.int32)
        w = warp_3d_affine(in_vol, out_shape, M)
        jitter[...,i] = w[...]
        transforms.append(gt)
    return jitter, transforms
예제 #2
0
wb0_cc, wb0_aff = load_nib(wb0_cc_name)

# Result using MI
wt1_mi_name = basedir + "\\warp\\SyNMI\\warpedDiff_SCIL_01_t1_strip_SCIL_01_b0_down_strip.nii.gz"
wt1_mi, wt1_aff = load_nib(wt1_mi_name)
wt1_b0up_mi_name = basedir + "\\warp\\SyNMI\\warpedDiff_SCIL_01_t1_strip_SCIL_01_b0_up_strip.nii.gz"
wt1_b0up_mi, wt1_aff = load_nib(wt1_b0up_mi_name)
wb0_mi_name = basedir + "\\warp\\SyNMI\\warpedDiff_SCIL_01_b0_down_strip_SCIL_01_t1_strip.nii.gz"
wb0_mi, wb0_aff = load_nib(wb0_mi_name)
wb0_up_mi_name = basedir + "\\warp\\SyNMI\\warpedDiff_SCIL_01_b0_up_strip_SCIL_01_t1_strip.nii.gz"
wb0_up_mi, wb0_up_aff = load_nib(wb0_up_mi_name)
A = readAntsAffine(basedir + reg_t1_toward_b0)
T = np.linalg.inv(t1_aff).dot(A.dot(b0_aff))
shape = np.array(b0.shape, dtype=np.int32)
wb0_mi_aligned = np.array(
    vfu.warp_3d_affine(wb0_mi.astype(np.float32), shape, T))

A = readAntsAffine(basedir + reg_t1_toward_b0_up)
T = np.linalg.inv(t1_aff).dot(A.dot(b0up_aff))
shape = np.array(b0.shape, dtype=np.int32)
wb0_up_mi_aligned = np.array(
    vfu.warp_3d_affine(wb0_up_mi.astype(np.float32), shape, T))

# Result using ECC
wt1_ecc_name = basedir + "\\warp\\SyNECC\\warpedDiff_SCIL_01_t1_strip_SCIL_01_b0_down_strip.nii.gz"
wt1_ecc, wt1_aff = load_nib(wt1_ecc_name)
wt1_b0up_ecc_name = basedir + "\\warp\\SyNECC\\warpedDiff_SCIL_01_t1_strip_SCIL_01_b0_up_strip.nii.gz"
wt1_b0up_ecc, wt1_aff = load_nib(wt1_b0up_ecc_name)
wb0_ecc_name = basedir + "\\warp\\SyNECC\\warpedDiff_SCIL_01_b0_down_strip_SCIL_01_t1_strip.nii.gz"
wb0_ecc, wb0_aff = load_nib(wb0_ecc_name)
wb0_up_ecc_name = basedir + "\\warp\\SyNECC\\warpedDiff_SCIL_01_b0_up_strip_SCIL_01_t1_strip.nii.gz"
예제 #3
0
                      [4.34051706e-03, 9.41918267e-01, -2.66525861e-01, 3.23579799e+01],
                      [5.34288908e-02, 2.90262026e-01, 9.80820307e-01, -1.46216651e+01],
                      [0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]])

"""
As we did in the 2D example, we would like to visualize (some slices of) the two
volumes by overlapping them over two channels of a color image. To do that we
need them to be sampled on the same grid, so let's first re-sample the moving
image on the static grid
"""

import dipy.align.vector_fields as vfu

transform = np.linalg.inv(moving_affine).dot(pre_align.dot(static_affine))
resampled = vfu.warp_3d_affine(moving.astype(np.float32), 
                                   np.asarray(static.shape, dtype=np.int32), 
                                   transform)
resampled = np.asarray(resampled)

"""
plot the overlapped middle slices of the volumes
"""

regtools.overlay_slices(static, resampled, None, 1, 'Static', 'Moving', 'input_3d.png')

"""
.. figure:: input_3d.png
   :align: center

   **Static image in red on top of the pre-aligned moving image (in green)**.
"""