def test_initialize_eigenanatomy_example(self): mat = np.random.randn(4, 100).astype('float32') init = ants.initialize_eigenanatomy(mat) img = ants.image_read(ants.get_ants_data('r16')) segs = ants.kmeans_segmentation(img, 3) init = ants.initialize_eigenanatomy(segs['segmentation'])
def test_example(self): img = ants.image_read(ants.get_ants_data('r16'), 2) img = ants.resample_image(img, (64, 64), 1, 0) mask = ants.get_mask(img) segs = ants.kmeans_segmentation(img, k=3, kmask=mask) thick = ants.kelly_kapowski(s=segs['segmentation'], g=segs['probabilityimages'][1], w=segs['probabilityimages'][2], its=45, r=0.5, m=1)
t1maskFromBold = ants.apply_transforms( t1, bmask, t1reg['invtransforms'], interpolator = 'nearestNeighbor' ) t1 = ants.n4_bias_field_correction( t1, t1mask, 8 ).n4_bias_field_correction( t1mask, 4 ) bmask = ants.apply_transforms( und, t1mask, t1reg['fwdtransforms'], interpolator = 'nearestNeighbor' ).morphology("close",3) ofn = rdir + "features/LS" + id + "_mask_py.nii.gz" ants.image_write( bmask, ofn ) t1toBOLD = ants.apply_transforms( und, t1, t1reg['fwdtransforms'] ) ofn = rdir + "features/LS" + id + "_t1ToBold_py.nii.gz" ants.image_write( t1toBOLD, ofn ) ## Tissue segmentation # a simple method ################################################ qt1 = ants.iMath_truncate_intensity( t1, 0, 0.95 ) t1seg = ants.kmeans_segmentation( qt1, 3, t1mask, 0.2 ) volumes = ants.label_stats( t1seg['segmentation'], t1seg['segmentation'] ) 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' )
def test_mask_image_example(self): myimage = ants.image_read(ants.get_ants_data('r16')) mask = myimage > myimage.mean() myimage_mask = ants.mask_image(myimage, mask, 3) seg = ants.kmeans_segmentation(myimage, 3) myimage_mask = ants.mask_image(myimage, seg['segmentation'], (1, 3))
def test_labels_to_matrix_example(self): fi = ants.image_read(ants.get_ants_data('r16')).resample_image( (60, 60), 1, 0) mask = fi > fi.mean() labs = ants.kmeans_segmentation(fi, 3)['segmentation'] labmat = ants.labels_to_matrix(labs, mask)
def test_label_stats_example(self): image = ants.image_read(ants.get_ants_data('r16'), 2) image = ants.resample_image(image, (64, 64), 1, 0) mask = image > image.mean() segs1 = ants.kmeans_segmentation(image, 3) stats = ants.label_stats(image, segs1['segmentation'])
def test_example(self): fi = ants.image_read(ants.get_ants_data('r16')) seg = ants.kmeans_segmentation(fi, 3) mask = ants.threshold_image(seg['segmentation'], 1, 1e15) priorseg = ants.prior_based_segmentation(fi, seg['probabilityimages'], mask, 0.25, 0.1, 3)
def test_example(self): fi = ants.image_read(ants.get_ants_data('r16')) seg = ants.kmeans_segmentation(fi, 3)['segmentation'] geom = ants.label_geometry_measures(seg, fi)
def test_example(self): fi = ants.image_read(ants.get_ants_data('r16')) fi = ants.n3_bias_field_correction(fi, 2) seg = ants.kmeans_segmentation(fi, 3)
def __init__(self, ants_image=[[0.0]], k=3, **options): import ants self.seg = ants.kmeans_segmentation(ants_image, k, **options) print(self.seg)
def test_mask_image_example(self): myimage = ants.image_read(ants.get_ants_data("r16")) mask = ants.get_mask(myimage) myimage_mask = ants.mask_image(myimage, mask, (2, 3)) seg = ants.kmeans_segmentation(myimage, 3) myimage_mask = ants.mask_image(myimage, seg["segmentation"], (1, 3))
def test_labels_to_matrix_example(self): fi = ants.image_read(ants.get_ants_data("r16")).resample_image( (60, 60), 1, 0) mask = ants.get_mask(fi) labs = ants.kmeans_segmentation(fi, 3)["segmentation"] labmat = ants.labels_to_matrix(labs, mask)
def test_label_stats_example(self): image = ants.image_read(ants.get_ants_data("r16"), 2) image = ants.resample_image(image, (64, 64), 1, 0) segs1 = ants.kmeans_segmentation(image, 3) stats = ants.label_stats(image, segs1["segmentation"])
def test_label_overlap_measures(self): r16 = ants.image_read(ants.get_ants_data('r16')) r64 = ants.image_read(ants.get_ants_data('r64')) s16 = ants.kmeans_segmentation(r16, 3)['segmentation'] s64 = ants.kmeans_segmentation(r64, 3)['segmentation'] stats = ants.label_overlap_measures(s16, s64)