antspymm 1.5.6__py3-none-any.whl → 1.5.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
antspymm/__init__.py CHANGED
@@ -140,5 +140,7 @@ from .mm import pet3d_summary
140
140
  from .mm import deformation_gradient_optimized
141
141
  from .mm import efficient_dwi_fit_voxelwise
142
142
  from .mm import generate_voxelwise_bvecs
143
+ from .mm import distortion_correct_bvecs
144
+
143
145
 
144
146
 
antspymm/mm.py CHANGED
@@ -135,6 +135,10 @@ import tensorflow as tf
135
135
  from multiprocessing import Pool
136
136
  import glob as glob
137
137
 
138
+ antspyt1w.set_global_scientific_computing_random_seed(
139
+ antspyt1w.get_global_scientific_computing_random_seed( )
140
+ )
141
+
138
142
  DATA_PATH = os.path.expanduser('~/.antspymm/')
139
143
 
140
144
  def version( ):
@@ -1881,7 +1885,7 @@ def timeseries_transform(transform, image, reference, interpolation='linear'):
1881
1885
  def timeseries_reg(
1882
1886
  image,
1883
1887
  avg_b0,
1884
- type_of_transform="Rigid",
1888
+ type_of_transform='antsRegistrationSyNRepro[r]',
1885
1889
  total_sigma=1.0,
1886
1890
  fdOffset=2.0,
1887
1891
  trim = 0,
@@ -1993,7 +1997,7 @@ def timeseries_reg(
1993
1997
  if temp.numpy().var() > 0:
1994
1998
  myrig = ants.registration(
1995
1999
  avg_b0, temp,
1996
- type_of_transform='BOLDRigid',
2000
+ type_of_transform='antsRegistrationSyNRepro[r]',
1997
2001
  outprefix=txprefix
1998
2002
  )
1999
2003
  if type_of_transform == 'SyN':
@@ -2138,6 +2142,40 @@ def bvec_reorientation( motion_parameters, bvecs, rebase=None ):
2138
2142
  bvecs[myidx,:] = np.dot( rebase, bvecs[myidx,:] )
2139
2143
  return bvecs
2140
2144
 
2145
+
2146
+ def distortion_correct_bvecs(bvecs, def_grad, A_img, A_ref):
2147
+ """
2148
+ Vectorized computation of voxel-wise distortion corrected b-vectors.
2149
+
2150
+ Parameters
2151
+ ----------
2152
+ bvecs : ndarray (N, 3)
2153
+ def_grad : ndarray (X, Y, Z, 3, 3) containing rotations derived from the deformation gradient
2154
+ A_img : ndarray (3, 3) direction matrix of the fixed image (target undistorted space)
2155
+ A_ref : ndarray (3, 3) direction matrix of the moving image (being corrected)
2156
+
2157
+ Returns
2158
+ -------
2159
+ bvecs_5d : ndarray (X, Y, Z, N, 3)
2160
+ """
2161
+ X, Y, Z = def_grad.shape[:3]
2162
+ N = bvecs.shape[0]
2163
+ # Combined rotation: R_voxel = A_ref.T @ A_img @ def_grad
2164
+ A = A_ref.T @ A_img
2165
+ R_voxel = np.einsum('ij,xyzjk->xyzik', A, def_grad) # (X, Y, Z, 3, 3)
2166
+ # Apply R_voxel.T @ bvecs
2167
+ # First, reshape R_voxel: (X*Y*Z, 3, 3)
2168
+ R_voxel_reshaped = R_voxel.reshape(-1, 3, 3)
2169
+ # Rotate all bvecs for each voxel
2170
+ # Output: (X*Y*Z, N, 3)
2171
+ rotated = np.einsum('vij,nj->vni', R_voxel_reshaped, bvecs)
2172
+ # Normalize
2173
+ norms = np.linalg.norm(rotated, axis=2, keepdims=True)
2174
+ rotated /= np.clip(norms, 1e-8, None)
2175
+ # Reshape back to (X, Y, Z, N, 3)
2176
+ bvecs_5d = rotated.reshape(X, Y, Z, N, 3)
2177
+ return bvecs_5d
2178
+
2141
2179
  def get_dti( reference_image, tensormodel, upper_triangular=True, return_image=False ):
2142
2180
  """
2143
2181
  extract DTI data from a dipy tensormodel
@@ -2486,7 +2524,7 @@ def dti_reg(
2486
2524
  bvals=None,
2487
2525
  bvecs=None,
2488
2526
  b0_idx=None,
2489
- type_of_transform="Rigid",
2527
+ type_of_transform="antsRegistrationSyNRepro[r]",
2490
2528
  total_sigma=3.0,
2491
2529
  fdOffset=2.0,
2492
2530
  mask_csf=False,
@@ -2617,7 +2655,7 @@ def dti_reg(
2617
2655
  else:
2618
2656
  bcsf = ab0 * 0 + 1
2619
2657
 
2620
- initrig = ants.registration( avg_b0, ab0,'BOLDRigid',outprefix=ofnG)
2658
+ initrig = ants.registration( avg_b0, ab0,'antsRegistrationSyNRepro[r]',outprefix=ofnG)
2621
2659
  deftx = ants.registration( avg_dwi, adw, 'SyNOnly',
2622
2660
  syn_metric='CC', syn_sampling=2,
2623
2661
  reg_iterations=[50,50,20],
@@ -2646,7 +2684,7 @@ def dti_reg(
2646
2684
  if temp.numpy().var() > 0:
2647
2685
  myrig = ants.registration(
2648
2686
  fixed, temp,
2649
- type_of_transform='BOLDRigid',
2687
+ type_of_transform='antsRegistrationSyNRepro[r]',
2650
2688
  outprefix=txprefix,
2651
2689
  **kwargs
2652
2690
  )
@@ -2725,7 +2763,7 @@ def dti_reg(
2725
2763
  def mc_reg(
2726
2764
  image,
2727
2765
  fixed=None,
2728
- type_of_transform="Rigid",
2766
+ type_of_transform="antsRegistrationSyNRepro[r]",
2729
2767
  mask=None,
2730
2768
  total_sigma=3.0,
2731
2769
  fdOffset=2.0,
@@ -2828,7 +2866,7 @@ def mc_reg(
2828
2866
  if temp.numpy().var() > 0:
2829
2867
  myrig = ants.registration(
2830
2868
  fixed, temp,
2831
- type_of_transform='Rigid',
2869
+ type_of_transform='antsRegistrationSyNRepro[r]',
2832
2870
  outprefix=ofnL+str(k).zfill(4)+"_",
2833
2871
  **kwargs
2834
2872
  )
@@ -3193,7 +3231,7 @@ def dewarp_imageset( image_list, initial_template=None,
3193
3231
  initial_template=initial_template,
3194
3232
  image_list=avglist,
3195
3233
  gradient_step=0.5, blending_weight=0.8,
3196
- iterations=iterations, **kwargs )
3234
+ iterations=iterations, verbose=False, **kwargs )
3197
3235
 
3198
3236
  # last - warp all images to this frame
3199
3237
  mocoplist = []
@@ -3201,7 +3239,7 @@ def dewarp_imageset( image_list, initial_template=None,
3201
3239
  reglist = []
3202
3240
  for k in range(len(image_list)):
3203
3241
  if imagetype == 3:
3204
- moco0 = ants.motion_correction( image=image_list[k], fixed=btp, type_of_transform='BOLDRigid' )
3242
+ moco0 = ants.motion_correction( image=image_list[k], fixed=btp, type_of_transform='antsRegistrationSyNRepro[r]' )
3205
3243
  mocoplist.append( moco0['motion_parameters'] )
3206
3244
  mocofdlist.append( moco0['FD'] )
3207
3245
  locavg = ants.slice_image( moco0['motion_corrected'], axis=3, idx=0 ) * 0.0
@@ -3418,13 +3456,13 @@ def get_average_rsf( x, min_t=10, max_t=35 ):
3418
3456
  max_t=x.shape[3]
3419
3457
  for myidx in range(min_t,max_t):
3420
3458
  b0 = ants.slice_image( x, axis=3, idx=myidx)
3421
- bavg = bavg + ants.registration(oavg,b0,'Rigid',outprefix=ofn)['warpedmovout']
3459
+ bavg = bavg + ants.registration(oavg,b0,'antsRegistrationSyNRepro[r]',outprefix=ofn)['warpedmovout']
3422
3460
  bavg = ants.iMath( bavg, 'Normalize' )
3423
3461
  oavg = ants.image_clone( bavg )
3424
3462
  bavg = oavg * 0.0
3425
3463
  for myidx in range(min_t,max_t):
3426
3464
  b0 = ants.slice_image( x, axis=3, idx=myidx)
3427
- bavg = bavg + ants.registration(oavg,b0,'Rigid',outprefix=ofn)['warpedmovout']
3465
+ bavg = bavg + ants.registration(oavg,b0,'antsRegistrationSyNRepro[r]',outprefix=ofn)['warpedmovout']
3428
3466
  import shutil
3429
3467
  shutil.rmtree(output_directory, ignore_errors=True )
3430
3468
  bavg = ants.iMath( bavg, 'Normalize' )
@@ -3463,16 +3501,16 @@ def get_average_dwi_b0( x, fixed_b0=None, fixed_dwi=None, fast=False ):
3463
3501
  temp_dwi = ants.slice_image( x, axis=3, idx=non_b0_idx[0] )
3464
3502
  xavg = fixed_b0 * 0.0
3465
3503
  bavg = fixed_b0 * 0.0
3466
- tempreg = ants.registration( fixed_b0, temp_b0,'BOLDRigid')
3504
+ tempreg = ants.registration( fixed_b0, temp_b0,'antsRegistrationSyNRepro[r]')
3467
3505
  fixed_b0_use = tempreg['warpedmovout']
3468
3506
  fixed_dwi_use = ants.apply_transforms( fixed_b0, temp_dwi, tempreg['fwdtransforms'] )
3469
3507
  for myidx in range(x.shape[3]):
3470
3508
  b0 = ants.slice_image( x, axis=3, idx=myidx)
3471
3509
  if not fast:
3472
3510
  if not myidx in b0_idx:
3473
- xavg = xavg + ants.registration(fixed_dwi_use,b0,'Rigid',outprefix=ofn)['warpedmovout']
3511
+ xavg = xavg + ants.registration(fixed_dwi_use,b0,'antsRegistrationSyNRepro[r]',outprefix=ofn)['warpedmovout']
3474
3512
  else:
3475
- bavg = bavg + ants.registration(fixed_b0_use,b0,'Rigid',outprefix=ofn)['warpedmovout']
3513
+ bavg = bavg + ants.registration(fixed_b0_use,b0,'antsRegistrationSyNRepro[r]',outprefix=ofn)['warpedmovout']
3476
3514
  else:
3477
3515
  if not myidx in b0_idx:
3478
3516
  xavg = xavg + b0
@@ -3484,7 +3522,7 @@ def get_average_dwi_b0( x, fixed_b0=None, fixed_dwi=None, fast=False ):
3484
3522
  shutil.rmtree(output_directory, ignore_errors=True )
3485
3523
  avgb0=ants.n4_bias_field_correction(bavg)
3486
3524
  avgdwi=ants.n4_bias_field_correction(xavg)
3487
- avgdwi=ants.registration( avgb0, avgdwi, 'Rigid' )['warpedmovout']
3525
+ avgdwi=ants.registration( avgb0, avgdwi, 'antsRegistrationSyNRepro[r]' )['warpedmovout']
3488
3526
  return avgb0, avgdwi
3489
3527
 
3490
3528
  def dti_template(
@@ -3530,8 +3568,8 @@ def dti_template(
3530
3568
  fimg2=bavg
3531
3569
  mimg2=b_image_list[k] * bcsf[k]
3532
3570
  w1 = ants.registration(
3533
- fimg, mimg, type_of_transform='antsRegistrationSyNQuick[s]',
3534
- multivariate_extras= [ [ "mattes", fimg2, mimg2, 1, 32 ]],
3571
+ fimg, mimg, type_of_transform='antsRegistrationSyNQuickRepro[s]',
3572
+ multivariate_extras= [ [ "CC", fimg2, mimg2, 1, 2 ]],
3535
3573
  outprefix=mydeftx,
3536
3574
  verbose=0 )
3537
3575
  txname = ants.apply_transforms(wavg, wavg,
@@ -3587,7 +3625,7 @@ def t1_based_dwi_brain_extraction(
3587
3625
  t1w,
3588
3626
  dwi,
3589
3627
  b0_idx = None,
3590
- transform='Rigid',
3628
+ transform='antsRegistrationSyNRepro[r]',
3591
3629
  deform=None,
3592
3630
  verbose=False
3593
3631
  ):
@@ -3625,7 +3663,7 @@ def t1_based_dwi_brain_extraction(
3625
3663
  b0_avg = ants.slice_image( dwi, axis=3, idx=b0_idx[0] ).iMath("Normalize")
3626
3664
  for n in range(1,len(b0_idx)):
3627
3665
  temp = ants.slice_image( dwi, axis=3, idx=b0_idx[n] )
3628
- reg = ants.registration( b0_avg, temp, 'Rigid' )
3666
+ reg = ants.registration( b0_avg, temp, 'antsRegistrationSyNRepro[r]' )
3629
3667
  b0_avg = b0_avg + ants.iMath( reg['warpedmovout'], "Normalize")
3630
3668
  else:
3631
3669
  b0_avg = ants.slice_image( dwi, axis=3, idx=b0_idx[0] )
@@ -4529,7 +4567,7 @@ def joint_dti_recon(
4529
4567
  print("JHU reg",flush=True)
4530
4568
 
4531
4569
  OR_FA2JHUreg = ants.registration( reconFA, jhu_atlas,
4532
- type_of_transform = 'SyN', syn_metric='CC', syn_sampling=2,
4570
+ type_of_transform = 'antsRegistrationSyNQuickRepro[s]',
4533
4571
  reg_iterations=reg_its, verbose=False )
4534
4572
  OR_FA_jhulabels = ants.apply_transforms( reconFA, jhu_labels,
4535
4573
  OR_FA2JHUreg['fwdtransforms'], interpolator='genericLabel')
@@ -5521,7 +5559,7 @@ def tra_initializer( fixed, moving, n_simulations=32, max_rotation=30,
5521
5559
  bestreg=compreg
5522
5560
  initx = ants.read_transform( bestreg['fwdtransforms'][0] )
5523
5561
  for mytx in transform:
5524
- regtx = 'Rigid'
5562
+ regtx = 'antsRegistrationSyNRepro[r]'
5525
5563
  with tempfile.NamedTemporaryFile(suffix='.h5') as tp:
5526
5564
  if mytx == 'translation':
5527
5565
  regtx = 'Translation'
@@ -5626,7 +5664,7 @@ def neuromelanin( list_nm_images, t1, t1_head, t1lab, brain_stem_dilation=8,
5626
5664
  templateNM = ants.iMath( mm_read( fntNM ), "Normalize" )
5627
5665
  templatebstem = mm_read( fntbst ).threshold_image( 1, 1000 )
5628
5666
  # reg = ants.registration( t1, template, 'antsRegistrationSyNQuickRepro[s]' )
5629
- reg = ants.registration( t1, template, 'SyN' )
5667
+ reg = ants.registration( t1, template, 'antsRegistrationSyNQuickRepro[s]' )
5630
5668
  # map NM avg to t1 for neuromelanin processing
5631
5669
  nmavg2t1 = ants.apply_transforms( t1, templateNM,
5632
5670
  reg['fwdtransforms'], interpolator='linear' )
@@ -5662,7 +5700,7 @@ def neuromelanin( list_nm_images, t1, t1_head, t1lab, brain_stem_dilation=8,
5662
5700
  if verbose:
5663
5701
  print(str(k) + " of " + str(len( list_nm_images ) ) )
5664
5702
  current_image = ants.registration( list_nm_images[k], nm_avg,
5665
- type_of_transform = 'Rigid' )
5703
+ type_of_transform = 'antsRegistrationSyNRepro[r]' )
5666
5704
  txlist.append( current_image['fwdtransforms'][0] )
5667
5705
  current_image = current_image['warpedfixout']
5668
5706
  nm_avg_new = nm_avg_new + current_image / len( list_nm_images )
@@ -5672,7 +5710,7 @@ def neuromelanin( list_nm_images, t1, t1_head, t1lab, brain_stem_dilation=8,
5672
5710
  print("do slab registration to map anatomy to NM space")
5673
5711
  t1c = ants.crop_image( t1_head, slab2t1 ).iMath("Normalize") # old way
5674
5712
  nmavg2t1c = ants.crop_image( nmavg2t1, slab2t1 ).iMath("Normalize")
5675
- # slabreg = ants.registration( nm_avg, nmavg2t1c, 'Rigid' )
5713
+ # slabreg = ants.registration( nm_avg, nmavg2t1c, 'antsRegistrationSyNRepro[r]' )
5676
5714
  slabreg = tra_initializer( nm_avg, t1c, verbose=verbose )
5677
5715
  if False:
5678
5716
  slabregT1 = tra_initializer( nm_avg, t1c, verbose=verbose )
@@ -5732,7 +5770,7 @@ def neuromelanin( list_nm_images, t1, t1_head, t1lab, brain_stem_dilation=8,
5732
5770
  myreg = ants.registration(
5733
5771
  ants.iMath(nm_avg_cropped,"Normalize"),
5734
5772
  ants.iMath(crop_nm_list[k],"Normalize"),
5735
- 'BOLDRigid' )
5773
+ 'antsRegistrationSyNRepro[r]' )
5736
5774
  warpednext = ants.apply_transforms(
5737
5775
  nm_avg_cropped_new,
5738
5776
  crop_nm_list[k],
@@ -6046,7 +6084,7 @@ def resting_state_fmri_networks( fmri, fmri_template, t1, t1segmentation,
6046
6084
  else:
6047
6085
  nc=float(nc)
6048
6086
 
6049
- type_of_transform='Rigid' # , # should probably not change this
6087
+ type_of_transform="antsRegistrationSyNQuickRepro[r]" # , # should probably not change this
6050
6088
  remove_it=True
6051
6089
  output_directory = tempfile.mkdtemp()
6052
6090
  output_directory_w = output_directory + "/ts_t1_reg/"
@@ -6155,13 +6193,14 @@ def resting_state_fmri_networks( fmri, fmri_template, t1, t1segmentation,
6155
6193
  trim = 8,
6156
6194
  output_directory=None,
6157
6195
  verbose=verbose,
6158
- syn_metric='cc',
6196
+ syn_metric='CC',
6159
6197
  syn_sampling=2,
6160
6198
  reg_iterations=[40,20,5],
6161
6199
  return_numpy_motion_parameters=True )
6162
6200
 
6163
6201
  if verbose:
6164
6202
  print("End rsfmri motion correction")
6203
+ print("--maximum motion : " + str(corrmo['FD'].max()) )
6165
6204
  print("=== next anatomically based mapping ===")
6166
6205
 
6167
6206
  despiking_count = np.zeros( corrmo['motion_corrected'].shape[3] )
@@ -6181,7 +6220,7 @@ def resting_state_fmri_networks( fmri, fmri_template, t1, t1segmentation,
6181
6220
  # anatomical mapping
6182
6221
  und = fmri_template * bmask
6183
6222
  t1reg = ants.registration( und, t1,
6184
- "SyNBold", outprefix=ofnt1tx )
6223
+ "antsRegistrationSyNQuickRepro[s]", outprefix=ofnt1tx )
6185
6224
  if verbose:
6186
6225
  print("t1 2 bold done")
6187
6226
  gmseg = ants.threshold_image( t1segmentation, 2, 2 )
@@ -6716,17 +6755,18 @@ def bold_perfusion_minimal(
6716
6755
  perf_total_sigma = 1.5
6717
6756
  corrmo = timeseries_reg(
6718
6757
  fmri, fmri_template,
6719
- type_of_transform='Rigid',
6758
+ type_of_transform='antsRegistrationSyNRepro[r]',
6720
6759
  total_sigma=perf_total_sigma,
6721
6760
  fdOffset=2.0,
6722
6761
  trim = mytrim,
6723
6762
  output_directory=None,
6724
6763
  verbose=verbose,
6725
- syn_metric='cc',
6764
+ syn_metric='CC',
6726
6765
  syn_sampling=2,
6727
6766
  reg_iterations=[40,20,5] )
6728
6767
  if verbose:
6729
6768
  print("End rsfmri motion correction")
6769
+ print("--maximum motion : " + str(corrmo['FD'].max()) )
6730
6770
 
6731
6771
  if m0_image is not None:
6732
6772
  m0 = m0_image
@@ -6755,17 +6795,18 @@ def bold_perfusion_minimal(
6755
6795
  fmri_template = ants.iMath( ants.get_average_of_timeseries( fmrimotcorr ), "Normalize" )
6756
6796
  corrmo = timeseries_reg(
6757
6797
  fmri, fmri_template,
6758
- type_of_transform='Rigid',
6798
+ type_of_transform='antsRegistrationSyNRepro[r]',
6759
6799
  total_sigma=perf_total_sigma,
6760
6800
  fdOffset=2.0,
6761
6801
  trim = mytrim,
6762
6802
  output_directory=None,
6763
6803
  verbose=verbose,
6764
- syn_metric='cc',
6804
+ syn_metric='CC',
6765
6805
  syn_sampling=2,
6766
6806
  reg_iterations=[40,20,5] )
6767
6807
  if verbose:
6768
6808
  print("End 2nd rsfmri motion correction")
6809
+ print("--maximum motion : " + str(corrmo['FD'].max()) )
6769
6810
 
6770
6811
  if outlier_threshold < 1.0 and outlier_threshold > 0.0:
6771
6812
  corrmo['motion_corrected'] = remove_volumes_from_timeseries( corrmo['motion_corrected'], hlinds )
@@ -6819,7 +6860,7 @@ def bold_perfusion_minimal(
6819
6860
  m0 = ants.get_average_of_timeseries( fmrimotcorr )
6820
6861
  else:
6821
6862
  # register m0 to current template
6822
- m0reg = ants.registration( fmri_template, m0, 'Rigid', verbose=False )
6863
+ m0reg = ants.registration( fmri_template, m0, 'antsRegistrationSyNRepro[r]', verbose=False )
6823
6864
  m0 = m0reg['warpedmovout']
6824
6865
 
6825
6866
  if ntp == 2 :
@@ -6900,7 +6941,7 @@ def bold_perfusion(
6900
6941
  FD_threshold=0.5,
6901
6942
  spa = (0., 0., 0., 0.),
6902
6943
  nc = 3,
6903
- type_of_transform='Rigid',
6944
+ type_of_transform='antsRegistrationSyNRepro[r]',
6904
6945
  tc='alternating',
6905
6946
  n_to_trim=0,
6906
6947
  m0_image = None,
@@ -7035,7 +7076,7 @@ def bold_perfusion(
7035
7076
  fmri_template, hlinds = loop_timeseries_censoring( fmri, 0.10 )
7036
7077
  fmri_template = ants.get_average_of_timeseries( fmri_template )
7037
7078
  del hlinds
7038
- rig = ants.registration( fmri_template, t1head, 'BOLDRigid' )
7079
+ rig = ants.registration( fmri_template, t1head, 'antsRegistrationSyNRepro[r]' )
7039
7080
  bmask = ants.apply_transforms( fmri_template, ants.threshold_image(t1segmentation,1,6), rig['fwdtransforms'][0], interpolator='genericLabel' )
7040
7081
  if m0_indices is None:
7041
7082
  if n_to_trim is None:
@@ -7052,7 +7093,7 @@ def bold_perfusion(
7052
7093
  trim = mytrim,
7053
7094
  output_directory=None,
7054
7095
  verbose=verbose,
7055
- syn_metric='cc',
7096
+ syn_metric='CC',
7056
7097
  syn_sampling=2,
7057
7098
  reg_iterations=[40,20,5] )
7058
7099
  if verbose:
@@ -7101,7 +7142,7 @@ def bold_perfusion(
7101
7142
  print( 'fmri_template')
7102
7143
  print( fmri_template )
7103
7144
 
7104
- rig = ants.registration( fmri_template, t1head, 'BOLDRigid' )
7145
+ rig = ants.registration( fmri_template, t1head, 'antsRegistrationSyNRepro[r]' )
7105
7146
  bmask = ants.apply_transforms( fmri_template,
7106
7147
  ants.threshold_image(t1segmentation,1,6),
7107
7148
  rig['fwdtransforms'][0],
@@ -7117,7 +7158,7 @@ def bold_perfusion(
7117
7158
  trim = mytrim,
7118
7159
  output_directory=None,
7119
7160
  verbose=verbose,
7120
- syn_metric='cc',
7161
+ syn_metric='CC',
7121
7162
  syn_sampling=2,
7122
7163
  reg_iterations=[40,20,5] )
7123
7164
  if verbose:
@@ -7230,7 +7271,7 @@ Where:
7230
7271
  m0 = ants.get_average_of_timeseries( fmrimotcorr )
7231
7272
  else:
7232
7273
  # register m0 to current template
7233
- m0reg = ants.registration( fmri_template, m0, 'Rigid', verbose=False )
7274
+ m0reg = ants.registration( fmri_template, m0, 'antsRegistrationSyNRepro[r]', verbose=False )
7234
7275
  m0 = m0reg['warpedmovout']
7235
7276
 
7236
7277
  if ntp == 2 :
@@ -7317,7 +7358,7 @@ Where:
7317
7358
 
7318
7359
  def pet3d_summary( pet3d, t1head, t1, t1segmentation, t1dktcit,
7319
7360
  spa = (0., 0., 0.),
7320
- type_of_transform='Rigid',
7361
+ type_of_transform='antsRegistrationSyNRepro[r]',
7321
7362
  upsample=True,
7322
7363
  verbose=False ):
7323
7364
  """
@@ -7367,7 +7408,7 @@ def pet3d_summary( pet3d, t1head, t1, t1segmentation, t1dktcit,
7367
7408
  newspc = [minspc,minspc,minspc]
7368
7409
  pet3dr = ants.resample_image( pet3d, newspc, interp_type=0 )
7369
7410
 
7370
- rig = ants.registration( pet3dr, t1head, 'BOLDRigid' )
7411
+ rig = ants.registration( pet3dr, t1head, 'antsRegistrationSyNRepro[r]' )
7371
7412
  bmask = ants.apply_transforms( pet3dr,
7372
7413
  ants.threshold_image(t1segmentation,1,6),
7373
7414
  rig['fwdtransforms'][0],
@@ -7502,7 +7543,7 @@ def mm(
7502
7543
  group_template = None,
7503
7544
  group_transform = None,
7504
7545
  target_range = [0,1],
7505
- dti_motion_correct = 'Rigid',
7546
+ dti_motion_correct = 'antsRegistrationSyNQuickRepro[r]',
7506
7547
  dti_denoise = False,
7507
7548
  perfusion_trim=10,
7508
7549
  perfusion_m0_image=None,
@@ -7645,9 +7686,10 @@ def mm(
7645
7686
 
7646
7687
  if do_kk:
7647
7688
  if verbose:
7648
- print('kk')
7649
- output_dict['kk'] = antspyt1w.kelly_kapowski_thickness( t1atropos,
7689
+ print('kk in mm')
7690
+ output_dict['kk'] = antspyt1w.kelly_kapowski_thickness( t1_image,
7650
7691
  labels=hier['dkt_parc']['dkt_cortex'], iterations=45 )
7692
+
7651
7693
  if perfusion_image is not None:
7652
7694
  if perfusion_image.shape[3] > 1: # FIXME - better heuristic?
7653
7695
  output_dict['perf'] = bold_perfusion(
@@ -7672,7 +7714,7 @@ def mm(
7672
7714
  verbose=verbose )
7673
7715
  ################################## do the rsf .....
7674
7716
  if len(rsf_image) > 0:
7675
- my_motion_tx = 'Rigid'
7717
+ my_motion_tx = 'antsRegistrationSyNRepro[r]'
7676
7718
  rsf_image = [i for i in rsf_image if i is not None]
7677
7719
  if verbose:
7678
7720
  print('rsf length ' + str( len( rsf_image ) ) )
@@ -7694,6 +7736,7 @@ def mm(
7694
7736
  boldTemplate = ants.build_template(
7695
7737
  initial_template = init_temp,
7696
7738
  image_list=[rsfavg1,rsfavg2],
7739
+ type_of_transform="antsRegistrationSyNQuickRepro[s]",
7697
7740
  iterations=5, verbose=False )
7698
7741
  if verbose:
7699
7742
  print("join the 2 rsf")
@@ -7765,89 +7808,7 @@ def mm(
7765
7808
  verbose=verbose ) # default
7766
7809
  rsfprolist.append( rsf0 )
7767
7810
  output_dict['rsf'] = rsfprolist
7768
- if False: # this is the old parameter search stuff
7769
- # Initialize the parameters DataFrame
7770
- # first - no censoring - just explore compcor
7771
- df = pd.DataFrame()
7772
- cens=False
7773
- HM=1.0 # best by PTBP
7774
- hmsearch = [0.5, 1.0, 5.0 ]
7775
- loopsearch = [ 0.25, 0.5, 0.75, 1.0 ]
7776
- loop = 1.0
7777
- CCsearch = [ 5, 0.80 ]
7778
- defaultf = [ 0.008, 0.15 ]
7779
- freqsearch = ['broad','mid','tight'] #
7780
- # for debuggin
7781
- # rsf_image = remove_volumes_from_timeseries( rsf_image, list(range(80,2000)))
7782
- docens=True # explore censoring
7783
- for ff in freqsearch:
7784
- for CC in CCsearch:
7785
- local_df = pd.DataFrame({"loop": [loop], "cens": [cens], "HM": [HM], "ff": [ff], "CC": [CC]})
7786
- if verbose:
7787
- print( local_df )
7788
- if df.shape[0] == 0:
7789
- df = local_df
7790
- else:
7791
- df = pd.concat([df, local_df], ignore_index=True)
7792
- f = defaultf
7793
- if ff == 'mid':
7794
- f = [0.01,0.1]
7795
- elif ff == 'tight':
7796
- f = [0.03,0.08]
7797
- rsf0 = resting_state_fmri_networks(
7798
- rsf_image, boldTemplate, hier['brain_n4_dnz'], t1atropos,
7799
- f=f,
7800
- FD_threshold=HM,
7801
- spa = None, spt = None,
7802
- nc = CC,
7803
- outlier_threshold=loop,
7804
- ica_components = 0,
7805
- impute = False,
7806
- censor = cens,
7807
- despike = 2.5,
7808
- motion_as_nuisance = True,
7809
- upsample=False,
7810
- clean_tmp=0.66,
7811
- verbose=verbose ) # default
7812
- rsfprolist.append( rsf0 )
7813
-
7814
- # test impact of censoring
7815
- if docens:
7816
- cens = True
7817
- for loop in loopsearch:
7818
- for HM in hmsearch:
7819
- for ff in freqsearch:
7820
- for CC in CCsearch:
7821
- local_df = pd.DataFrame({"loop": [loop], "cens": [cens], "HM": [HM], "ff": [ff], "CC": [CC]})
7822
- if verbose:
7823
- print( local_df )
7824
- df = pd.concat([df, local_df], ignore_index=True)
7825
- f = defaultf
7826
- if ff == 'mid':
7827
- f = [0.01,0.1]
7828
- elif ff == 'tight':
7829
- f = [0.03,0.08]
7830
- rsf0 = resting_state_fmri_networks(
7831
- rsf_image,
7832
- boldTemplate,
7833
- hier['brain_n4_dnz'],
7834
- t1atropos,
7835
- f=f,
7836
- FD_threshold=HM,
7837
- spa = None,
7838
- spt = None,
7839
- nc = CC,
7840
- outlier_threshold=loop,
7841
- ica_components = 0,
7842
- impute = False,
7843
- censor = cens,
7844
- despike = 2.5,
7845
- motion_as_nuisance = True,
7846
- upsample=False,
7847
- clean_tmp=0.66,
7848
- verbose=verbose ) # default
7849
- rsfprolist.append( rsf0 )
7850
- output_dict['rsf'] = rsfprolist
7811
+
7851
7812
  if nm_image_list is not None:
7852
7813
  if verbose:
7853
7814
  print('nm')
@@ -7864,11 +7825,11 @@ def mm(
7864
7825
  print("We have only one DTI: " + str(len(dw_image)))
7865
7826
  dw_image = dw_image[0]
7866
7827
  btpB0, btpDW = get_average_dwi_b0(dw_image)
7867
- initrig = ants.registration( btpDW, hier['brain_n4_dnz'], 'BOLDRigid' )['fwdtransforms'][0]
7828
+ initrig = ants.registration( btpDW, hier['brain_n4_dnz'], 'antsRegistrationSyNRepro[r]' )['fwdtransforms'][0]
7868
7829
  tempreg = ants.registration( btpDW, hier['brain_n4_dnz'], 'SyNOnly',
7869
- syn_metric='mattes', syn_sampling=32,
7830
+ syn_metric='CC', syn_sampling=2,
7870
7831
  reg_iterations=[50,50,20],
7871
- multivariate_extras=[ [ "mattes", btpB0, hier['brain_n4_dnz'], 1, 32 ]],
7832
+ multivariate_extras=[ [ "CC", btpB0, hier['brain_n4_dnz'], 1, 2 ]],
7872
7833
  initial_transform=initrig
7873
7834
  )
7874
7835
  mybxt = ants.threshold_image( ants.iMath(hier['brain_n4_dnz'], "Normalize" ), 0.001, 1 )
@@ -7901,11 +7862,11 @@ def mm(
7901
7862
  b_image_list=[a1b,a2b],
7902
7863
  w_image_list=[a1w,a2w],
7903
7864
  iterations=7, verbose=verbose )
7904
- initrig = ants.registration( btpDW, hier['brain_n4_dnz'], 'BOLDRigid' )['fwdtransforms'][0]
7865
+ initrig = ants.registration( btpDW, hier['brain_n4_dnz'], 'antsRegistrationSyNRepro[r]' )['fwdtransforms'][0]
7905
7866
  tempreg = ants.registration( btpDW, hier['brain_n4_dnz'], 'SyNOnly',
7906
- syn_metric='mattes', syn_sampling=32,
7867
+ syn_metric='CC', syn_sampling=2,
7907
7868
  reg_iterations=[50,50,20],
7908
- multivariate_extras=[ [ "mattes", btpB0, hier['brain_n4_dnz'], 1, 32 ]],
7869
+ multivariate_extras=[ [ "CC", btpB0, hier['brain_n4_dnz'], 1, 2 ]],
7909
7870
  initial_transform=initrig
7910
7871
  )
7911
7872
  mybxt = ants.threshold_image( ants.iMath(hier['brain_n4_dnz'], "Normalize" ), 0.001, 1 )
@@ -7992,7 +7953,7 @@ def mm(
7992
7953
  normalization_dict['kk_norm'] = ants.apply_transforms( group_template, output_dict['kk']['thickness_image'], group_transform )
7993
7954
  if output_dict['DTI'] is not None:
7994
7955
  mydti = output_dict['DTI']
7995
- dtirig = ants.registration( hier['brain_n4_dnz'], mydti['recon_fa'], 'Rigid' )
7956
+ dtirig = ants.registration( hier['brain_n4_dnz'], mydti['recon_fa'], 'antsRegistrationSyNRepro[r]' )
7996
7957
  normalization_dict['MD_norm'] = ants.apply_transforms( group_template, mydti['recon_md'],group_transform+dtirig['fwdtransforms'] )
7997
7958
  normalization_dict['FA_norm'] = ants.apply_transforms( group_template, mydti['recon_fa'],group_transform+dtirig['fwdtransforms'] )
7998
7959
  output_directory = tempfile.mkdtemp()
@@ -8009,7 +7970,7 @@ def mm(
8009
7970
  if output_dict['rsf'] is not None:
8010
7971
  if False:
8011
7972
  rsfpro = output_dict['rsf'] # FIXME
8012
- rsfrig = ants.registration( hier['brain_n4_dnz'], rsfpro['meanBold'], 'Rigid' )
7973
+ rsfrig = ants.registration( hier['brain_n4_dnz'], rsfpro['meanBold'], 'antsRegistrationSyNRepro[r]' )
8013
7974
  for netid in get_antsimage_keys( rsfpro ):
8014
7975
  rsfkey = netid + "_norm"
8015
7976
  normalization_dict[rsfkey] = ants.apply_transforms(
@@ -8763,7 +8724,7 @@ def mm_csv(
8763
8724
  srmodel_T1 = False, # optional - will add a great deal of time
8764
8725
  srmodel_NM = False, # optional - will add a great deal of time
8765
8726
  srmodel_DTI = False, # optional - will add a great deal of time
8766
- dti_motion_correct = 'SyN',
8727
+ dti_motion_correct = 'antsRegistrationSyNQuickRepro[r]',
8767
8728
  dti_denoise = True,
8768
8729
  nrg_modality_list = None,
8769
8730
  normalization_template = None,
@@ -10971,7 +10932,7 @@ def wmh( flair, t1, t1seg,
10971
10932
  """
10972
10933
  import numpy as np
10973
10934
  import math
10974
- t1_2_flair_reg = ants.registration(flair, t1, type_of_transform = 'Rigid') # Register T1 to Flair
10935
+ t1_2_flair_reg = ants.registration(flair, t1, type_of_transform = 'antsRegistrationSyNRepro[r]') # Register T1 to Flair
10975
10936
  if probability_mask is None and model == 'sysu':
10976
10937
  if verbose:
10977
10938
  print('sysu')
@@ -12622,7 +12583,7 @@ def enantiomorphic_filling_without_mask( image, axis=0, intensity='low' ):
12622
12583
  imagen = ants.iMath( imagen, "TruncateIntensity", 1e-6, 0.98 )
12623
12584
  imagen = ants.iMath( imagen, 'Normalize' )
12624
12585
  # Create a mirror image (flipping left and right)
12625
- mirror_image = ants.reflect_image(imagen, axis=0, tx='SyN' )['warpedmovout']
12586
+ mirror_image = ants.reflect_image(imagen, axis=0, tx='antsRegistrationSyNQuickRepro[s]' )['warpedmovout']
12626
12587
 
12627
12588
  # Create a symmetric version of the image by averaging the original and the mirror image
12628
12589
  symmetric_image = imagen * 0.5 + mirror_image * 0.5
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: antspymm
3
- Version: 1.5.6
3
+ Version: 1.5.9
4
4
  Summary: multi-channel/time-series medical image processing with antspyx
5
5
  Author-email: "Avants, Gosselin, Tustison, Reardon" <stnava@gmail.com>
6
6
  License: Apache-2.0
@@ -0,0 +1,6 @@
1
+ antspymm/__init__.py,sha256=cTcqtGO0J5T2I0Chxe-Sy25QDlnHLDEQK8QEnJkkFRs,4900
2
+ antspymm/mm.py,sha256=uAtsfULH9PLB1_mPRTt2rMzZvuPl3X526FYwfSENNmc,541908
3
+ antspymm-1.5.9.dist-info/METADATA,sha256=QKbK0ypvBfQblG-6VJFnr8md_lmnMn14lz5bchmg-_0,26007
4
+ antspymm-1.5.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ antspymm-1.5.9.dist-info/top_level.txt,sha256=iyD1sRhCKzfwKRJLq5ZUeV9xsv1cGQl8Ejp6QwXM1Zg,9
6
+ antspymm-1.5.9.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- antspymm/__init__.py,sha256=50wAFf04ZlF7wYg1h07dFLKebGOGFwKCJfAcdyHhSXw,4858
2
- antspymm/mm.py,sha256=mtkFJi0ZwLFw32vCrBdZcGa4ITgIOSn_Vfwq1SXLdqE,543752
3
- antspymm-1.5.6.dist-info/METADATA,sha256=0H4Olfd04VZNR56ErUfVd0hEo8DppIsDrWWbks0JgHs,26007
4
- antspymm-1.5.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- antspymm-1.5.6.dist-info/top_level.txt,sha256=iyD1sRhCKzfwKRJLq5ZUeV9xsv1cGQl8Ejp6QwXM1Zg,9
6
- antspymm-1.5.6.dist-info/RECORD,,