Example #1
0
def fitting_is_rotationally_invariant():
    pts0 = np.random.randn(200,3)
    pts1 = np.random.randn(200,3)
    
    bend_coef = 13.
    rot_coefs = np.ones(3)#np.random.rand(3)
    wt_n = np.random.rand(200)
    
    lin_ag, trans_g, w_ng = tps.tps_fit3(pts0, pts1, bend_coef, rot_coefs, wt_n, rot_target = np.eye(3))    
    
    # random rotation matrix
    A = np.random.randn(3,3)
    u,s,vh = np.linalg.svd(A.dot(A))
    R = u.dot(vh)
    
    lin1_ag, trans1_g, w1_ng = tps.tps_fit3(pts0, pts1.dot(R), bend_coef, rot_coefs, wt_n, rot_target = R)    
    
    assert np.allclose(lin_ag, lin1_ag.dot(R.T))
    assert np.allclose(trans1_g, trans_g.dot(R))
    assert np.allclose(w1_ng, w_ng.dot(R))
Example #2
0
def fit_ThinPlateSpline(x_na, y_ng, bend_coef=.1, rot_coef = 1e-5, wt_n=None):
    """
    x_na: source cloud
    y_nd: target cloud
    smoothing: penalize non-affine part
    angular_spring: penalize rotation
    wt_n: weight the points        
    """
    f = ThinPlateSpline()
    f.lin_ag, f.trans_g, f.w_ng = tps.tps_fit3(x_na, y_ng, bend_coef, rot_coef, wt_n)
    f.x_na = x_na
    return f        
Example #3
0
def fitting_methods_equivalent():
    pts0 = np.random.randn(100,3)
    pts1 = np.random.randn(100,3)
    lin_ag, trans_g, w_ng = tps.tps_fit(pts0, pts1, .01, 0)    
    lin2_ag, trans2_g, w2_ng = tps.tps_fit2(pts0, pts1, .01, 0)
    lin3_ag, trans3_g, w3_ng = tps.tps_fit3(pts0, pts1, .01, 0, np.ones(len(pts0)))
    assert np.allclose(lin_ag, lin2_ag)
    assert np.allclose(trans_g, trans2_g)
    assert np.allclose(w_ng, w2_ng)


    assert np.allclose(lin_ag, lin3_ag)
    assert np.allclose(trans_g, trans3_g)
    assert np.allclose(w_ng, w3_ng)

    lin2_ag, trans2_g, w2_ng = tps.tps_fit2(pts0, pts1, .01, .01)
    lin3_ag, trans3_g, w3_ng = tps.tps_fit3(pts0, pts1, .01, .01, np.ones(len(pts0)))

    assert np.allclose(lin2_ag, lin3_ag)
    assert np.allclose(trans2_g, trans3_g)
    assert np.allclose(w2_ng, w3_ng)
Example #4
0
def fit_ThinPlateSpline(x_na, y_ng, bend_coef=.1, rot_coef = 1e-5, wt_n=None):
    """
    x_na: source cloud
    y_nd: target cloud
    smoothing: penalize non-affine part
    angular_spring: penalize rotation
    wt_n: weight the points        
    """
    f = ThinPlateSpline()
    f.lin_ag, f.trans_g, f.w_ng = tps.tps_fit3(x_na, y_ng, bend_coef, rot_coef, wt_n)
    f.x_na = x_na
    return f        
Example #5
0
def fitting_methods_equivalent():
    pts0 = np.random.randn(100, 3)
    pts1 = np.random.randn(100, 3)
    lin_ag, trans_g, w_ng = tps.tps_fit(pts0, pts1, .01, 0)
    lin2_ag, trans2_g, w2_ng = tps.tps_fit2(pts0, pts1, .01, 0)
    lin3_ag, trans3_g, w3_ng = tps.tps_fit3(pts0, pts1, .01, 0,
                                            np.ones(len(pts0)))
    assert np.allclose(lin_ag, lin2_ag)
    assert np.allclose(trans_g, trans2_g)
    assert np.allclose(w_ng, w2_ng)

    assert np.allclose(lin_ag, lin3_ag)
    assert np.allclose(trans_g, trans3_g)
    assert np.allclose(w_ng, w3_ng)

    lin2_ag, trans2_g, w2_ng = tps.tps_fit2(pts0, pts1, .01, .01)
    lin3_ag, trans3_g, w3_ng = tps.tps_fit3(pts0, pts1, .01, .01,
                                            np.ones(len(pts0)))

    assert np.allclose(lin2_ag, lin3_ag)
    assert np.allclose(trans2_g, trans3_g)
    assert np.allclose(w2_ng, w3_ng)