antspymm 1.5.9__py3-none-any.whl → 1.6.0__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 +1 -3
- antspymm/mm.py +103 -6
- {antspymm-1.5.9.dist-info → antspymm-1.6.0.dist-info}/METADATA +3 -3
- antspymm-1.6.0.dist-info/RECORD +6 -0
- antspymm-1.5.9.dist-info/RECORD +0 -6
- {antspymm-1.5.9.dist-info → antspymm-1.6.0.dist-info}/WHEEL +0 -0
- {antspymm-1.5.9.dist-info → antspymm-1.6.0.dist-info}/top_level.txt +0 -0
antspymm/__init__.py
CHANGED
antspymm/mm.py
CHANGED
@@ -284,6 +284,85 @@ def validate_nrg_file_format(path, separator):
|
|
284
284
|
# If all checks pass
|
285
285
|
return True, "The path conforms to the NRG format."
|
286
286
|
|
287
|
+
|
288
|
+
|
289
|
+
def apply_transforms_mixed_interpolation(
|
290
|
+
fixed,
|
291
|
+
moving,
|
292
|
+
transformlist,
|
293
|
+
interpolator="linear",
|
294
|
+
imagetype=0,
|
295
|
+
whichtoinvert=None,
|
296
|
+
mask=None,
|
297
|
+
**kwargs
|
298
|
+
):
|
299
|
+
"""
|
300
|
+
Apply ANTs transforms with mixed interpolation:
|
301
|
+
- Linear interpolation inside `mask`
|
302
|
+
- Nearest neighbor outside `mask`
|
303
|
+
|
304
|
+
Parameters
|
305
|
+
----------
|
306
|
+
fixed : ANTsImage
|
307
|
+
Fixed/reference image to define spatial domain.
|
308
|
+
|
309
|
+
moving : ANTsImage
|
310
|
+
Moving image to be transformed.
|
311
|
+
|
312
|
+
transformlist : list of str
|
313
|
+
List of filenames for transforms.
|
314
|
+
|
315
|
+
interpolator : str, optional
|
316
|
+
Interpolator used inside the mask. Default is "linear".
|
317
|
+
|
318
|
+
imagetype : int
|
319
|
+
Image type used by ANTs (0 = scalar, 1 = vector, etc.)
|
320
|
+
|
321
|
+
whichtoinvert : list of bool, optional
|
322
|
+
List of booleans indicating which transforms to invert.
|
323
|
+
|
324
|
+
mask : ANTsImage
|
325
|
+
Binary mask image indicating where to apply `interpolator` (e.g., "linear").
|
326
|
+
Outside the mask, nearest neighbor is used.
|
327
|
+
|
328
|
+
kwargs : dict
|
329
|
+
Additional arguments passed to `ants.apply_transforms`.
|
330
|
+
|
331
|
+
Returns
|
332
|
+
-------
|
333
|
+
ANTsImage
|
334
|
+
Interpolated image using mixed interpolation, added across masked regions.
|
335
|
+
"""
|
336
|
+
if mask is None:
|
337
|
+
raise ValueError("A binary `mask` image must be provided.")
|
338
|
+
|
339
|
+
# Apply linear interpolation inside the mask
|
340
|
+
interp_linear = ants.apply_transforms(
|
341
|
+
fixed=fixed,
|
342
|
+
moving=moving,
|
343
|
+
transformlist=transformlist,
|
344
|
+
interpolator=interpolator,
|
345
|
+
imagetype=imagetype,
|
346
|
+
whichtoinvert=whichtoinvert,
|
347
|
+
**kwargs
|
348
|
+
)
|
349
|
+
|
350
|
+
# Apply nearest-neighbor interpolation everywhere
|
351
|
+
interp_nn = ants.apply_transforms(
|
352
|
+
fixed=fixed,
|
353
|
+
moving=moving,
|
354
|
+
transformlist=transformlist,
|
355
|
+
interpolator="nearestNeighbor",
|
356
|
+
imagetype=imagetype,
|
357
|
+
whichtoinvert=whichtoinvert,
|
358
|
+
**kwargs
|
359
|
+
)
|
360
|
+
|
361
|
+
# Combine: linear * mask + nn * (1 - mask)
|
362
|
+
mixed_result = (interp_linear * mask) + (interp_nn * (1 - mask))
|
363
|
+
|
364
|
+
return mixed_result
|
365
|
+
|
287
366
|
def get_antsimage_keys(dictionary):
|
288
367
|
"""
|
289
368
|
Return the keys of the dictionary where the values are ANTsImages.
|
@@ -2528,6 +2607,7 @@ def dti_reg(
|
|
2528
2607
|
total_sigma=3.0,
|
2529
2608
|
fdOffset=2.0,
|
2530
2609
|
mask_csf=False,
|
2610
|
+
brain_mask_eroded=None,
|
2531
2611
|
output_directory=None,
|
2532
2612
|
verbose=False, **kwargs
|
2533
2613
|
):
|
@@ -2556,6 +2636,8 @@ def dti_reg(
|
|
2556
2636
|
|
2557
2637
|
mask_csf: boolean
|
2558
2638
|
|
2639
|
+
brain_mask_eroded: optional mask that will trigger mixed interpolation
|
2640
|
+
|
2559
2641
|
output_directory : string
|
2560
2642
|
output will be placed in this directory plus a numeric extension.
|
2561
2643
|
|
@@ -2579,6 +2661,7 @@ def dti_reg(
|
|
2579
2661
|
-------
|
2580
2662
|
>>> import ants
|
2581
2663
|
"""
|
2664
|
+
|
2582
2665
|
idim = image.dimension
|
2583
2666
|
ishape = image.shape
|
2584
2667
|
nTimePoints = ishape[idim - 1]
|
@@ -2624,6 +2707,8 @@ def dti_reg(
|
|
2624
2707
|
ab0, adw = get_average_dwi_b0( image )
|
2625
2708
|
# mask is used to roughly locate middle of brain
|
2626
2709
|
mask = ants.threshold_image( ants.iMath(adw,'Normalize'), 0.1, 1.0 )
|
2710
|
+
if brain_mask_eroded is None:
|
2711
|
+
brain_mask_eroded = mask * 0 + 1
|
2627
2712
|
motion_parameters = list()
|
2628
2713
|
motion_corrected = list()
|
2629
2714
|
centerOfMass = mask.get_center_of_mass()
|
@@ -2721,9 +2806,9 @@ def dti_reg(
|
|
2721
2806
|
fixed=ants.image_clone( adw )
|
2722
2807
|
if temp.numpy().var() > 0:
|
2723
2808
|
motion_parameters[k]=deftx+motion_parameters[k]
|
2724
|
-
img1w =
|
2809
|
+
img1w = apply_transforms_mixed_interpolation( avg_dwi,
|
2725
2810
|
ants.slice_image(image, axis=idim - 1, idx=k),
|
2726
|
-
motion_parameters[k] )
|
2811
|
+
motion_parameters[k], mask=brain_mask_eroded )
|
2727
2812
|
motion_corrected.append(img1w)
|
2728
2813
|
else:
|
2729
2814
|
motion_corrected.append(fixed)
|
@@ -4467,10 +4552,12 @@ def joint_dti_recon(
|
|
4467
4552
|
if denoise :
|
4468
4553
|
img_RL = mc_denoise( img_RL )
|
4469
4554
|
|
4555
|
+
brainmaske = None
|
4470
4556
|
if brain_mask is not None:
|
4471
4557
|
maskInRightSpace = ants.image_physical_space_consistency( brain_mask, reference_B0 )
|
4472
4558
|
if not maskInRightSpace :
|
4473
4559
|
raise ValueError('not maskInRightSpace ... provided brain mask should be in reference_B0 space')
|
4560
|
+
brainmaske = ants.iMath( maskInRightSpace, "ME", 2 )
|
4474
4561
|
|
4475
4562
|
if img_RL is not None :
|
4476
4563
|
if verbose:
|
@@ -4482,6 +4569,7 @@ def joint_dti_recon(
|
|
4482
4569
|
bvals=bval_RL,
|
4483
4570
|
bvecs=bvec_RL,
|
4484
4571
|
type_of_transform=motion_correct,
|
4572
|
+
brain_mask_eroded=brainmaske,
|
4485
4573
|
verbose=True )
|
4486
4574
|
else:
|
4487
4575
|
reg_RL=None
|
@@ -4496,6 +4584,7 @@ def joint_dti_recon(
|
|
4496
4584
|
bvals=bval_LR,
|
4497
4585
|
bvecs=bvec_LR,
|
4498
4586
|
type_of_transform=motion_correct,
|
4587
|
+
brain_mask_eroded=brainmaske,
|
4499
4588
|
verbose=True )
|
4500
4589
|
|
4501
4590
|
ts_LR_avg = None
|
@@ -5520,7 +5609,7 @@ def get_rsf_outputs( coords ):
|
|
5520
5609
|
return list( yeo['SystemName'].unique() )
|
5521
5610
|
|
5522
5611
|
def tra_initializer( fixed, moving, n_simulations=32, max_rotation=30,
|
5523
|
-
transform=['rigid'], compreg=None, verbose=False ):
|
5612
|
+
transform=['rigid'], compreg=None, random_seed=42, verbose=False ):
|
5524
5613
|
"""
|
5525
5614
|
multi-start multi-transform registration solution - based on ants.registration
|
5526
5615
|
|
@@ -5536,9 +5625,14 @@ def tra_initializer( fixed, moving, n_simulations=32, max_rotation=30,
|
|
5536
5625
|
|
5537
5626
|
compreg : registration results against which to compare
|
5538
5627
|
|
5628
|
+
random_seed : random seed for reproducibility
|
5629
|
+
|
5539
5630
|
verbose : boolean
|
5540
5631
|
|
5541
5632
|
"""
|
5633
|
+
import random
|
5634
|
+
if random_seed is not None:
|
5635
|
+
random.seed(random_seed)
|
5542
5636
|
if True:
|
5543
5637
|
output_directory = tempfile.mkdtemp()
|
5544
5638
|
output_directory_w = output_directory + "/tra_reg/"
|
@@ -7176,7 +7270,7 @@ def bold_perfusion(
|
|
7176
7270
|
warn_if_small_mask( bmask, label='bold_perfusion:bmask*tsnrmask')
|
7177
7271
|
fmrimotcorr=corrmo['motion_corrected']
|
7178
7272
|
und = fmri_template * bmask
|
7179
|
-
t1reg = ants.registration( und, t1, "
|
7273
|
+
t1reg = ants.registration( und, t1, "antsRegistrationSyNRepro[s]" )
|
7180
7274
|
gmseg = ants.threshold_image( t1segmentation, 2, 2 )
|
7181
7275
|
gmseg = gmseg + ants.threshold_image( t1segmentation, 4, 4 )
|
7182
7276
|
gmseg = ants.threshold_image( gmseg, 1, 4 )
|
@@ -7808,7 +7902,7 @@ def mm(
|
|
7808
7902
|
verbose=verbose ) # default
|
7809
7903
|
rsfprolist.append( rsf0 )
|
7810
7904
|
output_dict['rsf'] = rsfprolist
|
7811
|
-
|
7905
|
+
|
7812
7906
|
if nm_image_list is not None:
|
7813
7907
|
if verbose:
|
7814
7908
|
print('nm')
|
@@ -7890,7 +7984,7 @@ def mm(
|
|
7890
7984
|
mydti = output_dict['DTI']
|
7891
7985
|
# summarize dwi with T1 outputs
|
7892
7986
|
# first - register ....
|
7893
|
-
reg = ants.registration( mydti['recon_fa'], hier['brain_n4_dnz'], '
|
7987
|
+
reg = ants.registration( mydti['recon_fa'], hier['brain_n4_dnz'], 'antsRegistrationSyNRepro[s]', total_sigma=1.0 )
|
7894
7988
|
##################################################
|
7895
7989
|
output_dict['FA_summ'] = hierarchical_modality_summary(
|
7896
7990
|
mydti['recon_fa'],
|
@@ -9993,7 +10087,10 @@ def augment_image( x, max_rot=10, nzsd=1 ):
|
|
9993
10087
|
|
9994
10088
|
def boot_wmh( flair, t1, t1seg, mmfromconvexhull = 0.0, strict=True,
|
9995
10089
|
probability_mask=None, prior_probability=None, n_simulations=16,
|
10090
|
+
random_seed = 42,
|
9996
10091
|
verbose=False ) :
|
10092
|
+
import random
|
10093
|
+
random.seed( random_seed )
|
9997
10094
|
if verbose and prior_probability is None:
|
9998
10095
|
print("augmented flair")
|
9999
10096
|
if verbose and prior_probability is not None:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: antspymm
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.6.0
|
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
|
@@ -13,8 +13,8 @@ Requires-Dist: h5py>=2.10.0
|
|
13
13
|
Requires-Dist: numpy>=1.19.4
|
14
14
|
Requires-Dist: pandas>=1.0.1
|
15
15
|
Requires-Dist: antspyx>=0.4.2
|
16
|
-
Requires-Dist: antspynet>=0.
|
17
|
-
Requires-Dist: antspyt1w>=
|
16
|
+
Requires-Dist: antspynet>=0.3.0
|
17
|
+
Requires-Dist: antspyt1w>=1.1.0
|
18
18
|
Requires-Dist: pathlib
|
19
19
|
Requires-Dist: dipy
|
20
20
|
Requires-Dist: nibabel
|
@@ -0,0 +1,6 @@
|
|
1
|
+
antspymm/__init__.py,sha256=4_mZOfEtK-8BwT9qds8XMsr9r8ukVNUd00q6pngZHWQ,4950
|
2
|
+
antspymm/mm.py,sha256=2XzDbTWWcKIzJuYYPjEuwLmShsiMgrZoWzaBtljeKo8,544619
|
3
|
+
antspymm-1.6.0.dist-info/METADATA,sha256=yQ-GUGbKV4Ni1aZdVoCAKEUE6JXduzXZ-F5ya3QPHko,26007
|
4
|
+
antspymm-1.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
5
|
+
antspymm-1.6.0.dist-info/top_level.txt,sha256=iyD1sRhCKzfwKRJLq5ZUeV9xsv1cGQl8Ejp6QwXM1Zg,9
|
6
|
+
antspymm-1.6.0.dist-info/RECORD,,
|
antspymm-1.5.9.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
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,,
|
File without changes
|
File without changes
|