Beispiel #1
0
def test_basic_2d_similarity():
    linear_component = np.array([[2, -6],
                                 [6, 2]])
    translation_component = np.array([7, -8])
    h_matrix = np.eye(3, 3)
    h_matrix[:-1, :-1] = linear_component
    h_matrix[:-1, -1] = translation_component
    similarity = Similarity(h_matrix)
    x = np.array([[0, 1],
                  [1, 1],
                  [-1, -5],
                  [3, -5]])
    # transform x explicitly
    solution = np.dot(x, linear_component.T) + translation_component
    # transform x using the affine transform
    result = similarity.apply(x)
    # check that both answers are equivalent
    assert_allclose(solution, result)
    # create several copies of x
    x_copies = np.array([x, x, x, x, x, x, x, x])
    # transform all of copies at once using the affine transform
    results = similarity.apply(x_copies)
    # check that all copies have been transformed correctly
    for r in results:
        assert_allclose(solution, r)
Beispiel #2
0
def test_similarity_2d_as_vector():
    params = np.array([0.2, 0.1, 1.0, 2.0])
    h**o = np.array([[params[0] + 1.0, -params[1], params[2]],
                     [params[1], params[0] + 1.0, params[3]], [0.0, 0.0, 1.0]])

    vec = Similarity(h**o).as_vector()

    assert_allclose(vec, params)
Beispiel #3
0
def test_align_2d_similarity():
    linear_component = np.array([[2, -6], [6, 2]])
    translation_component = np.array([7, -8])
    h_matrix = np.eye(3, 3)
    h_matrix[:-1, :-1] = linear_component
    h_matrix[:-1, -1] = translation_component
    similarity = Similarity(h_matrix)
    source = PointCloud(np.array([[0, 1], [1, 1], [-1, -5], [3, -5]]))
    target = similarity.apply(source)
    # estimate the transform from source and target
    estimate = AlignmentSimilarity(source, target)
    # check the estimates is correct
    assert_allclose(similarity.h_matrix, estimate.h_matrix)
Beispiel #4
0
def test_align_2d_similarity_set_h_matrix_raises_notimplemented_error():
    linear_component = np.array([[2, -6], [6, 2]])
    translation_component = np.array([7, -8])
    h_matrix = np.eye(3, 3)
    h_matrix[:-1, :-1] = linear_component
    h_matrix[:-1, -1] = translation_component
    similarity = Similarity(h_matrix)
    source = PointCloud(np.array([[0, 1], [1, 1], [-1, -5], [3, -5]]))
    target = similarity.apply(source)
    # estimate the transform from source to source
    estimate = AlignmentSimilarity(source, source)
    # and set the target
    estimate.set_h_matrix(h_matrix)
Beispiel #5
0
def test_similarity_3d_n_parameters_raises_notimplementederror():
    h**o = np.eye(4)
    t = Similarity(h**o)
    with raises(NotImplementedError):
        t.n_parameters
Beispiel #6
0
def test_similarity_2d_n_parameters():
    h**o = np.eye(3)
    t = Similarity(h**o)
    assert(t.n_parameters == 4)
Beispiel #7
0
def test_similarity_set_h_matrix_raises_notimplementederror():
    s = Similarity(np.eye(3))
    s.set_h_matrix(s.h_matrix)
Beispiel #8
0
def test_similarity_3d_n_parameters_raises_notimplementederror():
    h**o = np.eye(4)
    t = Similarity(h**o)
    # Raises exception
    t.n_parameters
Beispiel #9
0
def test_similarity_jacobian_3d_raises_dimensionalityerror():
    t = Similarity(np.eye(4))
    t.d_dp(np.ones([2, 3]))