コード例 #1
0
ファイル: util.py プロジェクト: TheLaueLab/point-alignment
def degrade(reference, rotation, translation, scale, drop, duplications, noise):
    from numpy import delete
    from coherent_point_drift.geometry import rotationMatrix, rigidXform
    from itertools import chain, repeat

    points = delete(reference, drop, axis=0)
    rotation_matrix = rotationMatrix(*rotation)
    indices = chain.from_iterable(repeat(i, n) for i, n in enumerate(duplications))
    return rigidXform(points, rotation_matrix, translation, scale)[list(indices)] + noise
コード例 #2
0
def test_cpd_prior():
    from coherent_point_drift.align import driftRigid
    rng = np.random.RandomState(4)

    ndim = 3

    R = rotationMatrix(*next(randomRotations(ndim, rng)))
    t = rng.normal(size=ndim)
    s = rng.normal(size=1)[0]

    X = rng.normal(size=(10, ndim))
    Y = RigidXform(R, t, s) @ X

    _, cpd = last(islice(driftRigid(X, Y, w=np.eye(len(X))), 200))
    ls = align(X, Y)
    np.testing.assert_almost_equal(cpd.R, ls.R)
    np.testing.assert_almost_equal(cpd.t, ls.t)
    np.testing.assert_almost_equal(cpd.s, ls.s)
コード例 #3
0
def test_cpd_prior():
    from coherent_point_drift.align import driftRigid
    rng = np.random.RandomState(4)

    ndim = 3

    R = rotationMatrix(*next(randomRotations(ndim, rng)))
    t = rng.normal(size=ndim)
    s = rng.normal(size=1)[0]

    X = rng.normal(size=(10, ndim))
    Y = RigidXform(R, t, s) @ X

    _, cpd = last(islice(driftRigid(X, Y, w=np.eye(len(X))), 200))
    ls = align(X, Y)
    np.testing.assert_almost_equal(cpd.R, ls.R)
    np.testing.assert_almost_equal(cpd.t, ls.t)
    np.testing.assert_almost_equal(cpd.s, ls.s)
コード例 #4
0
def test_least_squares():
    rng = np.random.RandomState(4)

    ndim = 3

    R = rotationMatrix(*next(randomRotations(ndim, rng)))
    t = rng.normal(size=ndim)
    s = rng.lognormal(size=1)[0]
    xform = RigidXform(R, t, s)

    X = rng.normal(size=(10, ndim))
    Y = xform @ X

    alignment = align(X, Y)
    expected = xform.inverse

    np.testing.assert_almost_equal(alignment.R, expected.R)
    np.testing.assert_almost_equal(alignment.t, expected.t)
    np.testing.assert_almost_equal(alignment.s, expected.s)
    np.testing.assert_almost_equal(alignment @ Y, X)
コード例 #5
0
def test_least_squares():
    rng = np.random.RandomState(4)

    ndim = 3

    R = rotationMatrix(*next(randomRotations(ndim, rng)))
    t = rng.normal(size=ndim)
    s = rng.lognormal(size=1)[0]
    xform = RigidXform(R, t, s)

    X = rng.normal(size=(10, ndim))
    Y = xform @ X

    alignment = align(X, Y)
    expected = xform.inverse

    np.testing.assert_almost_equal(alignment.R, expected.R)
    np.testing.assert_almost_equal(alignment.t, expected.t)
    np.testing.assert_almost_equal(alignment.s, expected.s)
    np.testing.assert_almost_equal(alignment @ Y, X)