コード例 #1
0
ファイル: test_graph.py プロジェクト: eosulliv/menpo
        [0, 1, 1, 0, 0, 0],
        [1, 0, 1, 1, 0, 0],
        [1, 1, 0, 0, 1, 0],
        [0, 1, 0, 0, 1, 1],
        [0, 0, 1, 1, 0, 0],
        [0, 0, 0, 1, 0, 0],
    ]
)
g_undirected = UndirectedGraph(adj_undirected)
pg_undirected = PointUndirectedGraph(points, adj_undirected)

# Define directed graph and pointgraph
adj_directed = csr_matrix(
    ([1] * 8, ([1, 2, 1, 2, 1, 2, 3, 3], [0, 0, 2, 1, 3, 4, 4, 5])), shape=(6, 6)
)
g_directed = DirectedGraph(adj_directed)
pg_directed = PointDirectedGraph(points, adj_directed)

# Define tree and pointtree
adj_tree = np.array(
    [
        [0, 1, 1, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 1, 1, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 1, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 1, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 1, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 1],
        [0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0],
    ]
コード例 #2
0
ファイル: builder.py プロジェクト: nontas/antonakoscvpr2015
    def __init__(self,
                 adjacency_array_appearance=None,
                 gaussian_per_patch=True,
                 adjacency_array_deformation=None,
                 root_vertex_deformation=None,
                 adjacency_array_shape=None,
                 features=no_op,
                 patch_shape=(17, 17),
                 normalization_diagonal=None,
                 n_levels=2,
                 downscale=2,
                 scaled_shape_models=False,
                 use_procrustes=True,
                 max_shape_components=None,
                 n_appearance_parameters=None):
        # check parameters
        checks.check_n_levels(n_levels)
        checks.check_downscale(downscale)
        checks.check_normalization_diagonal(normalization_diagonal)
        max_shape_components = checks.check_max_components(
            max_shape_components, n_levels, 'max_shape_components')
        features = checks.check_features(features, n_levels)
        n_appearance_parameters = _check_n_parameters(
            n_appearance_parameters, n_levels, 'n_appearance_parameters')

        # appearance graph
        if adjacency_array_appearance is None:
            self.graph_appearance = None
        elif adjacency_array_appearance == 'yorgos':
            self.graph_appearance = 'yorgos'
        else:
            self.graph_appearance = UndirectedGraph(adjacency_array_appearance)

        # shape graph
        if adjacency_array_shape is None:
            self.graph_shape = None
        else:
            self.graph_shape = UndirectedGraph(adjacency_array_shape)

        # check adjacency_array_deformation, root_vertex_deformation
        if adjacency_array_deformation is None:
            self.graph_deformation = None
            if root_vertex_deformation is None:
                self.root_vertex = 0
        else:
            if root_vertex_deformation is None:
                self.graph_deformation = DirectedGraph(
                    adjacency_array_deformation)
            else:
                self.graph_deformation = Tree(adjacency_array_deformation,
                                              root_vertex_deformation)

        # store parameters
        self.features = features
        self.patch_shape = patch_shape
        self.normalization_diagonal = normalization_diagonal
        self.n_levels = n_levels
        self.downscale = downscale
        self.scaled_shape_models = scaled_shape_models
        self.max_shape_components = max_shape_components
        self.n_appearance_parameters = n_appearance_parameters
        self.use_procrustes = use_procrustes
        self.gaussian_per_patch = gaussian_per_patch
コード例 #3
0
import numpy as np
from numpy.testing import assert_allclose
from nose.tools import raises

from menpo.shape import UndirectedGraph, DirectedGraph, Tree

# Define adjacency arrays
adj_undirected = np.array([[0, 1], [0, 2], [1, 2], [1, 3], [2, 4], [3, 4],
                           [3, 5]])
g_undirected = UndirectedGraph(adj_undirected)
adj_directed = np.array([[1, 0], [2, 0], [1, 2], [2, 1], [1, 3], [2, 4],
                         [3, 4], [3, 5]])
g_directed = DirectedGraph(adj_directed)
adj_tree = np.array([[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 6], [4, 7],
                     [5, 8]])
g_tree = Tree(adj_tree, 0)


@raises(ValueError)
def test_create_graph_exception():
    adj = np.array([[0, 1, 3], [0, 2, 4]])
    UndirectedGraph(adj)


@raises(ValueError)
def test_create_tree_exception_1():
    adj = np.array([[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [3, 6], [4, 7],
                    [5, 8], [0, 4]])
    Tree(adj, 0)