Esempio n. 1
0
    def test1(self):
        import ants
        import numpy as np
        # this fails because ConvertScalarImageToRGB is not wrapped
        img = ants.image_read(ants.get_data('r16'), pixeltype='unsigned char')
        # img_rgb = img.scalar_to_rgb()
        # img_vec = img_rgb.rgb_to_vector()

        # rgb_arr = img_rgb.numpy()
        # vec_arr = img_vec.numpy()
        print(np.allclose(img.numpy(), img.numpy()))
Esempio n. 2
0
import os
os.environ[ "ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS" ] = "4"
os.environ[ "ANTS_RANDOM_SEED" ] = "3"
import ants
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from numpy.polynomial import Legendre
from scipy import linalg
from scipy.stats.stats import pearsonr
# exec(open("src/sfJointReg.py").read())
powers_areal_mni_itk = pd.read_csv(ants.get_data('powers_mni_itk'))
rdir = "../"
id = '2001'
t1fn = rdir + 'data/LS' + id + "/unprocessed/3T/T1w_MPR1/LS"+id+"_3T_T1w_MPR1_gdc.nii.gz"
# now the bold data
boldfnsL = rdir + "data/LS2001/LS2001fmri/unprocessed/3T/rfMRI_REST1_LR/LS2001_3T_rfMRI_REST1_LR_gdc.nii.gz"
boldfnsR = rdir + "data/LS2001/LS2001fmri/unprocessed/3T/rfMRI_REST1_RL/LS2001_3T_rfMRI_REST1_RL_gdc.nii.gz"
# get the ref data
reffns1 = rdir + 'data/LS2001/LS2001fmri/unprocessed/3T/rfMRI_REST1_LR/LS2001_3T_rfMRI_REST1_LR_SBRef_gdc.nii.gz'
reffns2 = rdir + 'data/LS2001/LS2001fmri/unprocessed/3T/rfMRI_REST1_RL/LS2001_3T_rfMRI_REST1_RL_SBRef_gdc.nii.gz'

##  Distortion correction (without a field map)

i1 = ants.image_read( reffns1 )
i2 = ants.image_read( reffns2 )
und = ants.build_template( i1, ( i1, i2 ), 3, gradient_step = 0.5 )
t1 = ants.image_read( t1fn ).n3_bias_field_correction( 8 ).n3_bias_field_correction( 4 )
bmask = ants.get_mask( und, low_thresh = und.mean() * 0.75, high_thresh=1e9, cleanup = 3 ).iMath_fill_holes()
# ants.plot( und, bmask, axis=2, overlay_alpha = 0.33 )
# this is a fragile approach - not really recommended - but it is quick
Esempio n. 3
0
 def test_get_ants_data_files2(self):
     datanames = ants.get_data(None)
     self.assertTrue(isinstance(datanames, list))
     self.assertTrue(len(datanames) > 0)
Esempio n. 4
0
 def test_get_ants_data2(self):
     for dataname in ants.get_data(None):
         if dataname.endswith('nii.gz'):
             img = ants.image_read(dataname)
Esempio n. 5
0
 def test_RandomRotate3D_example(self):
     img = ants.image_read(ants.get_data('ch2'))
     tx = ants.contrib.RandomRotate3D(rotation_range=(-10, 10))
     img2 = tx.transform(img)
Esempio n. 6
0
 def test_Rotate3D_example(self):
     img = ants.image_read(ants.get_data('ch2'))
     tx = ants.contrib.Rotate3D(rotation=(10, -5, 12))
     img2 = tx.transform(img)
Esempio n. 7
0
 def test_RandomZoom3D_example(self):
     img = ants.image_read(ants.get_data('ch2'))
     tx = ants.contrib.RandomZoom3D(zoom_range=(0.8, 0.9))
     img2 = tx.transform(img)
Esempio n. 8
0
 def test_Zoom3D_example(self):
     img = ants.image_read(ants.get_data('ch2'))
     tx = ants.contrib.Zoom3D(zoom=(0.8, 0.8, 0.8))
     img2 = tx.transform(img)
import ants

fi = ants.image_read(ants.get_data("r16"))
mi = ants.image_read(ants.get_data("r64"))
tx = "Affine"
pnum = 0
tx = "SyN"
pnum = 1
metrics = ["MeanSquares", "GC", "Mattes"]
asr = 1
for m in range(0, len(metrics)):
    mytx1 = ants.registration(
        fixed=fi,
        moving=mi,
        type_of_transform=tx,
        aff_metric=metrics[m],
        aff_random_sampling_rate=asr,
    )
    p1 = ants.read_transform(mytx1["fwdtransforms"][pnum])
    p1 = ants.get_ants_transform_parameters(p1)
    for k in range(0, 2):
        mytx2 = ants.registration(
            fixed=fi,
            moving=mi,
            type_of_transform=tx,
            aff_metric=metrics[m],
            aff_random_sampling_rate=asr,
        )
        p2 = ants.read_transform(mytx2["fwdtransforms"][pnum])
        p2 = ants.get_ants_transform_parameters(p2)
        metval = ants.image_mutual_information(fi, mytx2["warpedmovout"])