Exemplo n.º 1
0
        print('Fitting CSD')
        print("sh_order: ", sh_order)
        print("fa_thr: ", fa_thr)
        response, ratio = auto_response(gtab,
                                        data,
                                        roi_radius=10,
                                        fa_thr=fa_thr)
        model = ConstrainedSphericalDeconvModel(gtab,
                                                response,
                                                sh_order=sh_order)
        sh_coeffs = model.fit(data).shm_coeff
    elif model_type == 'Opdt':
        print('Orientation Probability Density Transform')
        print("sh_order: ", sh_order)
        print("smooth: ", smooth)
        model = OpdtModel(gtab=gtab, sh_order=sh_order, smooth=smooth)
        sh_coeffs = model.fit(data, mask=mask).shm_coeff
    else:
        raise ValueError(
            'Model type not supported. Available models: 3D-SHORE, CSA-QBALL, SFM, CSD, Opdt'
        )

    if odf is not None:
        odf = np.nan_to_num(odf)
        print('Preparing ODF image')
        odf_image = sitk.Image([data.shape[2], data.shape[1], data.shape[0]],
                               sitk.sitkVectorFloat32, len(sphere.vertices))
        for x in range(data.shape[2]):
            for y in range(data.shape[1]):
                for z in range(data.shape[0]):
                    if mask is not None and mask[z, y, x] == 0:
Exemplo n.º 2
0
qballmodel = QballModel(gtab, 4, smooth=0.006)
print 'Computing the QBALL odf...'
coeff = qballmodel._get_shm_coef(data)
print coeff.shape

print 'Computing GFA...'
print np.min(coeff[:,:,:,0]),np.max(coeff[:,:,:,0])
gfa_sh = np.sqrt(1.0 - (coeff[:,:,:,0] ** 2 / ( np.sum(np.square(coeff), axis=3) ) ) )
gfa_sh[np.isnan(gfa_sh)] = 0

print 'Saving nifti...'
nib.save(nib.Nifti1Image(gfa_sh.astype('float32'), affine), 'gfa_qball_full_brain.nii.gz')    
nib.save(nib.Nifti1Image(coeff.astype('float32'), affine), 'qball_odf_sh.nii.gz')


opdtmodel = OpdtModel(gtab, 4, smooth=0.006)
print 'Computing the OPDT odf...'
coeff = opdtmodel._get_shm_coef(data)
print coeff.shape

print 'Computing GFA...'
print np.min(coeff[:,:,:,0]),np.max(coeff[:,:,:,0])
gfa_sh = np.sqrt(1.0 - (coeff[:,:,:,0] ** 2 / ( np.sum(np.square(coeff), axis=3) ) ) )
gfa_sh[np.isnan(gfa_sh)] = 0

print 'Saving nifti...'
nib.save(nib.Nifti1Image(gfa_sh.astype('float32'), affine), 'gfa_opdt_full_brain.nii.gz')    
nib.save(nib.Nifti1Image(coeff.astype('float32'), affine), 'opdt_odf_sh.nii.gz')


Exemplo n.º 3
0
if args.roi_nifti is not None:
    roi = get_img(args.roi_nifti)
    roi_data = roi.get_fdata()
else:
    roi_data = np.zeros(data.shape[:3])
    roi_data[FA > 0.1] = 1.

# Create seeds for ROI
seed_mask = utils.seeds_from_mask(roi_data,
                                  density=args.sampling_density,
                                  affine=np.eye(4))

# Setup model
print('slowadcodf')
sh_order = 6
model = OpdtModel(gtab, sh_order=sh_order, min_signal=1)

# Setup direction getter args
print('Bootstrap direction getter')
#boot_dg = BootDirectionGetter.from_data(data, model, max_angle=60., sphere=small_sphere)
b0s_mask = gtab.b0s_mask
dwi_mask = ~b0s_mask

# get fit_matrix from model
fit_matrix = model._fit_matrix
delta_b, delta_q = fit_matrix

# setup sampling matrix
sphere = small_sphere
theta = sphere.theta
phi = sphere.phi
Exemplo n.º 4
0
nib.save(nib.Nifti1Image(coeff.astype('float32'), affine), 'qball_odf_sh.nii.gz')


if vizu :
    odfs = sh_to_sf(coeff[20:50,55:85, 38:39], sphere, order)
    fvtk.add(r, fvtk.sphere_funcs(odfs, sphere, colormap='jet'))
    fvtk.show(r)
    fvtk.clear(r)

    #min-max normalize
    odfs = (odfs - np.min(odfs, -1)[..., None]) / (np.max(odfs, -1) - np.min(odfs, -1))[..., None]
    fvtk.add(r, fvtk.sphere_funcs(odfs, sphere, colormap='jet'))
    fvtk.show(r)
    fvtk.clear(r)


opdtmodel = OpdtModel(gtab, order, smooth=0.006)
print 'Computing the Opdt odf...'
opdtfit = opdtmodel.fit(data) 
coeff   = opdtfit._shm_coef
#GFA     = opdtfit.gfa
#nib.save(nib.Nifti1Image(GFA.astype('float32'), affine), 'gfa_opdt.nii.gz')    
nib.save(nib.Nifti1Image(coeff.astype('float32'), affine), 'opdt_odf_sh.nii.gz')

if vizu :
    odfs = sh_to_sf(coeff[20:50,55:85, 38:39], sphere, order)
    fvtk.add(r, fvtk.sphere_funcs(odfs, sphere, colormap='jet'))
    fvtk.show(r)
    fvtk.clear(r)