Beispiel #1
0
def test_init_from_edges():
    g = PointDirectedGraph.init_from_edges(
        points,
        np.array([[1, 0], [2, 0], [1, 2], [2, 1], [1, 3], [2, 4], [3, 4],
                  [3, 5]]))
    assert (pg_directed.adjacency_matrix - g.adjacency_matrix).nnz == 0
    g = PointUndirectedGraph.init_from_edges(
        points,
        np.array([[0, 1], [0, 2], [1, 2], [1, 3], [2, 4], [3, 4], [3, 5]]))
    assert (pg_undirected.adjacency_matrix - g.adjacency_matrix).nnz == 0
    g = PointUndirectedGraph.init_from_edges(
        points,
        np.array([[0, 1], [1, 0], [0, 2], [2, 0], [1, 2], [2, 1], [1, 3],
                  [3, 1], [2, 4], [4, 2], [3, 4], [4, 3], [3, 5], [5, 3]]))
    assert (pg_undirected.adjacency_matrix - g.adjacency_matrix).nnz == 0
    g = PointTree.init_from_edges(points2,
                                  np.array([[0, 1], [0, 2], [1, 3], [1, 4],
                                            [2, 5], [3, 6], [4, 7], [5, 8]]),
                                  root_vertex=0)
    assert (pg_tree.adjacency_matrix - g.adjacency_matrix).nnz == 0
    g = PointUndirectedGraph.init_from_edges(
        points, np.array([[0, 2], [2, 4], [3, 4]]))
    assert (pg_isolated.adjacency_matrix - g.adjacency_matrix).nnz == 0
    g = PointDirectedGraph.init_from_edges(point, np.array([]))
    assert (pg_single.adjacency_matrix - g.adjacency_matrix).nnz == 0
def test_init_from_edges():
    g = PointDirectedGraph.init_from_edges(
        points, np.array([[1, 0], [2, 0], [1, 2], [2, 1], [1, 3], [2, 4],
                          [3, 4], [3, 5]]))
    assert (pg_directed.adjacency_matrix - g.adjacency_matrix).nnz == 0
    g = PointUndirectedGraph.init_from_edges(
        points, np.array([[0, 1], [0, 2], [1, 2], [1, 3], [2, 4], [3, 4],
                          [3, 5]]))
    assert (pg_undirected.adjacency_matrix - g.adjacency_matrix).nnz == 0
    g = PointUndirectedGraph.init_from_edges(
        points, np.array([[0, 1], [1, 0], [0, 2], [2, 0], [1, 2], [2, 1],
                          [1, 3], [3, 1], [2, 4], [4, 2], [3, 4], [4, 3],
                          [3, 5], [5, 3]]))
    assert (pg_undirected.adjacency_matrix - g.adjacency_matrix).nnz == 0
    g = PointTree.init_from_edges(
        points2, np.array([[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 6],
                           [4, 7], [5, 8]]), root_vertex=0)
    assert (pg_tree.adjacency_matrix - g.adjacency_matrix).nnz == 0
    g = PointUndirectedGraph.init_from_edges(
        points, np.array([[0, 2], [2, 4], [3, 4]]))
    assert (pg_isolated.adjacency_matrix - g.adjacency_matrix).nnz == 0
    g = PointDirectedGraph.init_from_edges(point, np.array([]))
    assert (pg_single.adjacency_matrix - g.adjacency_matrix).nnz == 0
Beispiel #3
0
def test_pointgraph_view_widget():
    with raises(MenpowidgetsMissingError):
        PointDirectedGraph.init_from_edges(triangle_pcloud2d,
                                           [[0, 1], [1, 2]]).view_widget()
Beispiel #4
0
from mock import MagicMock
import numpy as np
from numpy.testing import assert_allclose

from menpo.shape import PointDirectedGraph
from menpodetect.detect import (detect, menpo_image_to_uint8)
import menpo.io as mio

takeo = mio.import_builtin_asset.takeo_ppm()
takeo_uint8 = mio.import_image(mio.data_path_to('takeo.ppm'), normalize=False)
fake_box = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
fake_detector = lambda x: ([
    PointDirectedGraph.init_from_edges(
        fake_box.copy(), np.array([[0, 1], [1, 2], [2, 3], [3, 0]]))
])


def test_rescaling_image():
    takeo_copy = takeo.copy()
    ratio = 200.0 / takeo_copy.diagonal()
    pcs = detect(fake_detector, takeo_copy, image_diagonal=200)
    assert len(pcs) == 1
    assert takeo_copy.n_channels == 3
    assert takeo_copy.landmarks['object_0'].n_points == 4
    assert_allclose(takeo_copy.landmarks['object_0'].points,
                    fake_box * (1.0 / ratio),
                    atol=10e-2)


def test_passing_uint8_image():
    takeo_copy = takeo_uint8.copy()
Beispiel #5
0
from mock import MagicMock
import numpy as np
from numpy.testing import assert_allclose

from menpo.shape import PointDirectedGraph
from menpodetect.detect import (detect, menpo_image_to_uint8)
import menpo.io as mio


takeo = mio.import_builtin_asset.takeo_ppm()
takeo_uint8 = mio.import_image(mio.data_path_to('takeo.ppm'), normalize=False)
fake_box = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
fake_detector = lambda x: ([PointDirectedGraph.init_from_edges(
    fake_box.copy(),
    np.array([[0, 1], [1, 2], [2, 3], [3, 0]]))])


def test_rescaling_image():
    takeo_copy = takeo.copy()
    ratio = 200.0 / takeo_copy.diagonal()
    pcs = detect(fake_detector, takeo_copy, image_diagonal=200)
    assert len(pcs) == 1
    assert takeo_copy.n_channels == 3
    assert takeo_copy.landmarks['object_0'][None].n_points == 4
    assert_allclose(takeo_copy.landmarks['object_0'][None].points,
                    fake_box * (1.0 / ratio), atol=10e-2)


def test_passing_uint8_image():
    takeo_copy = takeo_uint8.copy()
    pcs = detect(fake_detector, takeo_copy, greyscale=False)
def pointgraph_view_widget_test():
    PointDirectedGraph.init_from_edges(triangle_pcloud2d,
                                       [[0, 1], [1, 2]]).view_widget()
def pointgraph_view_widget_test():
    PointDirectedGraph.init_from_edges(triangle_pcloud2d,
                                       [[0, 1], [1, 2]]).view_widget()