def pointtrans(Fish, F):
    #===============================================================================
    import os
    import ants
    import pandas as pd
    import numpy as np

    # Apply registration to the CMN identified cells
    #---------------------------------------------------------------------------
    for c in range(len(Fish["Cond"])):
        print('Transforming points to standard space for condition ' +
              str(c + 1))
        Freg = F["Freg"] + os.sep + Fish["Name"] + os.sep + Fish["Cond"][c][
            "Name"]
        Ff2cf = Freg + os.sep + 'FUN2CF'
        os.listdir(Ff2cf)

        cs = pd.DataFrame(Fish["Cond"][c]["Pixels"])
        cs.columns = ['x', 'y', 'z']
        tcs = np.multiply(cs, (-.3, .3, -6))

        ncs = ants.apply_transforms_to_points(3, tcs, \
                                       [ Ff2cf +os.sep+ 'cf2fun_R.mat',
                                         Ff2cf +os.sep+ 'cf2fun_S.mat',
                                         Ff2cf +os.sep+ 'cf2fun_S.nii.gz'],  \
                                       whichtoinvert = [True, True, False])

        tcs = np.multiply(ncs, (1, 1, 1))
        nncs = ants.apply_transforms_to_points(3, tcs, \
                                        [ F["Ftrans"] +os.sep+ 'ref2cf_R.mat',
                                          F["Ftrans"] +os.sep+ 'ref2cf_S.mat',
                                          F["Ftrans"] +os.sep+ 'ref2cf_S.nii.gz'], \
                                        whichtoinvert = [True,True,False])

        Fish["Cond"][c]["ZBBCoord"] = nncs.values

    return Fish
Пример #2
0
boldseg = ants.apply_transforms( und, t1seg['segmentation'],
  t1reg['fwdtransforms'], interpolator = 'nearestNeighbor' )

## Template mapping
# include prior information e.g. from meta-analysis or anatomy

myvoxes = range(powers_areal_mni_itk.shape[0])
anat = powers_areal_mni_itk['Anatomy']
syst = powers_areal_mni_itk['SystemName']
Brod = powers_areal_mni_itk['Brodmann']
xAAL  = powers_areal_mni_itk['AAL']
ch2 = ants.image_read( ants.get_ants_data( "ch2" ) )
treg = ants.registration( t1 * t1mask, ch2, 'SyN' )

concatx2 = treg['invtransforms'] + t1reg['invtransforms']
pts2bold = ants.apply_transforms_to_points( 3, powers_areal_mni_itk, concatx2,whichtoinvert = ( True, False, True, False ) )
locations = pts2bold.iloc[:,:3].values
ptImg = ants.make_points_image( locations, bmask, radius = 3 )
networks = powers_areal_mni_itk['SystemName'].unique()
dfnpts = np.where( powers_areal_mni_itk['SystemName'] == networks[5] )
dfnImg = ants.mask_image(  ptImg, ptImg, level = dfnpts[0].tolist(), binarize=False )

# plot( und, ptImg, axis=3, window.overlay = range( ptImg ) )

bold2ch2 = ants.apply_transforms( ch2, und,  concatx2, whichtoinvert = ( True, False, True, False ) )


# Extracting canonical functional network maps
## preprocessing

csfAndWM = ( ants.threshold_image( boldseg, 1, 1 ) +
Пример #3
0
    initial_transform='AffineFast',
    type_of_transform='ElasticSyN',
    grad_step=5,
    aff_metric='mattes',
    aff_sampling=32,
    syn_metric='mattes',
    syn_sampling=32,
    reg_iterations=(40, 20, 10),
)
print('Transform: %r' % mytx)
t_elapsed = time.time() - t_start
print('Time: %r seconds' % t_elapsed)
warped_moving = ants.apply_transforms(fixed=fixed,
                                      moving=moving,
                                      transformlist=mytx['fwdtransforms'])
warped_points = ants.apply_transforms_to_points(
    dim=2, points=lnds, transformlist=mytx['invtransforms'])

# # Visualisation
# import matplotlib.pyplot as plt
# plt.imshow(warped_moving.numpy(), cmap=plt.cm.Greys_r)
# plt.plot(warped_points['y'], warped_points['x'], '.')
# plt.show()

# Exporting results
with open(paths['time'], 'w') as fp:
    fp.write(str(t_elapsed))
imsave(paths['warped'], warped_moving.numpy())
lnds = warped_points[['y', 'x']]
# transform landmarks coordinates back
lnds.columns = ['X', 'Y']
lnds.to_csv(paths['pts'])