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"])
        chg = abs(p2 - p1).sum()
        print(metrics[m] + " Change: try " + str(k) + " Is " + str(chg) +
              " Similarity= " + str(metval))
Beispiel #2
0
 def test_example(self):
     fi = ants.image_read(ants.get_ants_data('r16')).clone('float')
     mi = ants.image_read(ants.get_ants_data('r64')).clone('float')
     mival = ants.image_mutual_information(fi, mi)  # -0.1796141
Beispiel #3
0
 def test_example(self):
     fi = ants.image_read(ants.get_ants_data("r16")).clone("float")
     mi = ants.image_read(ants.get_ants_data("r64")).clone("float")
     mival = ants.image_mutual_information(fi, mi)  # -0.1796141
Beispiel #4
0
# -*- coding:utf-8 -*-
import ants
img1 = ants.image_read(
    '../mmwhs/CT_test/205_5/ct-image_crop_man_reg_resize/ct_train_1013_image.nii.gz'
)
img2 = ants.image_read(
    '../mmwhs/CT_test/205_5/ct-image_crop_man_reg_resize/ct_train_1014_image.nii.gz'
)
print(img2)
print(img1)
g1 = ants.iMath_grad(img1)
g2 = ants.iMath_grad(img2)

reg1 = ants.registration(img1, img2, 'SyNOnly')
demonsMetric = ['demons', g1, g2, 1, 1]
ccMetric = ['CC', img1, img2, 2, 4]
metrics = list()
metrics.append(demonsMetric)
print("start to registration...........")
reg2 = ants.registration(img1, img2, 'SyNOnly', multivariate_extras=metrics)
metrics.append(ccMetric)
reg3 = ants.registration(img1, img2, 'SyNOnly', multivariate_extras=metrics)

print(ants.image_mutual_information(img1, img2))
print(ants.image_mutual_information(img1, reg1['warpedmovout']))
print(ants.image_mutual_information(img1, reg2['warpedmovout']))
print(ants.image_mutual_information(img1, reg3['warpedmovout']))