示例#1
0
    # Applying optimal re-parameterization to the second curve
    beta2n = fs.group_action_by_gamma_coord(beta2, gamI)
    q2n = fs.curve_to_q(beta2n)

    if rotation:
        beta2n, O2, tau = fs.find_rotation_and_seed_coord(beta1, beta2n)
        centroid2 = fs.calculatecentroid(beta2n)
        beta2n = beta2n - np.tile(centroid2, [T, 1]).T
        q2n = fs.curve_to_q(beta2n)
        O = O1.dot(O2)
else:
    q2n = q2
    O = O1

# Forming geodesic between the registered curves
dist = np.arccos(fs.innerprod_q(q1, q2n))
if returnpath:
    PsiQ = np.zeros((n, T, k))
    PsiX = PsiQ
    for tau in range(0, k):
        s = dist * tau / (k - 1)
        PsiQ[:, :,
             tau] = (np.sin(dist - s) * q1 + np.sin(s) * q2n) / np.sin(dist)
        PsiX[:, :, tau] = fs.q_to_curve(PsiQ[:, :, tau])

    path = PsiQ
else:
    path = 0

if Disp_registration_between_curves:
    centroid1 = fs.calculatecentroid(beta1)
示例#2
0
eps = np.finfo(np.double).eps
gam = np.linspace(0, 1, TT)
psi = np.sqrt(np.abs(np.gradient(gam, binsize)) + eps)
gam_old = gam
psi_old = psi

itr = 0
max_val = np.zeros(max_itr+1)
while itr <= max_itr:
    A = np.zeros(m)
    Adiff = np.zeros((TT, m))
    qtmp = np.interp((time[-1] - time[0]) * gam_old + time[0], time, q)
    qtmp_diff = np.interp((time[-1] - time[0]) * gam_old + time[0],
                          time, np.gradient(q, binsize))
    for i in range(0, m):
        A[i] = fs.innerprod_q(time, qtmp * psi_old, beta[:, i])
        tmp1 = trapz(qtmp_diff * psi_old * beta[:, i], time)
        tmp2 = cumtrapz(qtmp_diff * psi_old * beta[:, i], time, initial=0)
        tmp = tmp1 - tmp2
        Adiff[:, i] = 2 * psi_old * tmp + qtmp * beta[:, i]

    tmp1 = np.sum(np.exp(alpha + A))
    tmp2 = np.sum(np.exp(alpha + A) * Adiff, axis=1)
    h = np.sum(y * Adiff, axis=1) - (tmp2 / tmp1)

    tmp = fs.innerprod_q(time, h, psi_old)
    vec = h - tmp*psi_old
    vecnorm = norm(vec) * binsize
    costmp = np.cos(delta * vecnorm) * psi_old
    sintmp = np.sin(delta * vecnorm) * (vec / vecnorm)
    psi_new = costmp + sintmp
示例#3
0
    # Applying optimal re-parameterization to the second curve
    beta2n = fs.group_action_by_gamma_coord(beta2, gamI)
    q2n = fs.curve_to_q(beta2n)

    if rotation:
        beta2n, O2, tau = fs.find_rotation_and_seed_coord(beta1, beta2n)
        centroid2 = fs.calculatecentroid(beta2n)
        beta2n = beta2n - np.tile(centroid2, [T, 1]).T
        q2n = fs.curve_to_q(beta2n)
        O = O1.dot(O2)
else:
    q2n = q2
    O = O1

# Forming geodesic between the registered curves
dist = np.arccos(fs.innerprod_q(q1, q2n))
if returnpath:
    PsiQ = np.zeros((n, T, k))
    PsiX = PsiQ
    for tau in range(0, k):
        s = dist * tau / (k - 1)
        PsiQ[:, :, tau] = (np.sin(dist-s)*q1+np.sin(s)*q2n)/np.sin(dist)
        PsiX[:, :, tau] = fs.q_to_curve(PsiQ[:, :, tau])

    path = PsiQ
else:
    path = 0

if Disp_registration_between_curves:
    centroid1 = fs.calculatecentroid(beta1)
    beta1 = beta1 - np.tile(centroid1, [T, 1]).T
eps = np.finfo(np.double).eps
gam = np.linspace(0, 1, TT)
psi = np.sqrt(np.abs(np.gradient(gam, binsize)) + eps)
gam_old = gam
psi_old = psi

itr = 0
max_val = np.zeros(max_itr + 1)
while itr <= max_itr:
    A = np.zeros(m)
    Adiff = np.zeros((TT, m))
    qtmp = np.interp((time[-1] - time[0]) * gam_old + time[0], time, q)
    qtmp_diff = np.interp((time[-1] - time[0]) * gam_old + time[0], time,
                          np.gradient(q, binsize))
    for i in range(0, m):
        A[i] = fs.innerprod_q(time, qtmp * psi_old, beta[:, i])
        tmp1 = trapz(qtmp_diff * psi_old * beta[:, i], time)
        tmp2 = cumtrapz(qtmp_diff * psi_old * beta[:, i], time, initial=0)
        tmp = tmp1 - tmp2
        Adiff[:, i] = 2 * psi_old * tmp + qtmp * beta[:, i]

    tmp1 = np.sum(np.exp(alpha + A))
    tmp2 = np.sum(np.exp(alpha + A) * Adiff, axis=1)
    h = np.sum(y * Adiff, axis=1) - (tmp2 / tmp1)

    tmp = fs.innerprod_q(time, h, psi_old)
    vec = h - tmp * psi_old
    vecnorm = norm(vec) * binsize
    costmp = np.cos(delta * vecnorm) * psi_old
    sintmp = np.sin(delta * vecnorm) * (vec / vecnorm)
    psi_new = costmp + sintmp