superdsm.atoms
- class superdsm.atoms.AtomAdjacencyGraph(atoms, clusters, fg_mask, seeds, out=None)
Bases:
object
Graph representation of the adjacencies of atomic image regions.
This corresponds to the adjacency graph \(\mathcal G\) as defined in Coarse-to-fine region analysis.
- Parameters:
atoms – Integer-valued image representing the universe of atomic image regions. Each atomic image region has a unique label, which is the integer value.
clusters – Integer-valued image representing the regions of possibly clustered obejcts. Each region has a unique label, which is the integer value.
fg_mask – Binary image corresponding to a rough representation of the image foreground. This means that an image point \(x \in \Omega\) is
True
if \(Y_\omega|_{\omega=\{x\}} > 0\) andFalse
otherwise.seeds – The seed points which were used to determine the atomic image regions, represented by a list of tuples of coordinates. The Default pipeline only uses these for rendering the adjacency graph (see the
get_edge_lines()
method).out – An instance of an
Output
sub-class,'muted'
if no output should be produced, orNone
if the default output should be used.
>>> import superdsm.atoms >>> import numpy as np >>> atoms = np.array([[1, 1, 2, 4], ... [1, 3, 2, 4], ... [3, 3, 3, 4]]) >>> clusters = np.array([[1, 1, 2, 2], ... [1, 2, 2, 2], ... [2, 2, 2, 2]]) >>> fg_mask = np.array([[True, False, True, False], ... [True, False, True, True], ... [True, True, True, True]]) >>> seeds = [(0, 0), (0, 2), (2, 1), (1, 3)] >>> adj = superdsm.atoms.AtomAdjacencyGraph(atoms, clusters, fg_mask, seeds, 'muted') >>> adj[1] set() >>> adj[2] {3, 4} >>> adj[3] {2, 4} >>> adj[4] {2, 3}
- property atom_labels
The set of labels of all atomic image regions.
>>> import superdsm.atoms >>> import numpy as np >>> atoms = np.array([[1, 1, 2, 4], ... [1, 3, 2, 4], ... [3, 3, 3, 4]]) >>> clusters = np.array([[1, 1, 2, 2], ... [1, 2, 2, 2], ... [2, 2, 2, 2]]) >>> fg_mask = np.ones(atoms.shape, bool) >>> seeds = [(0, 0), (0, 2), (2, 1), (1, 3)] >>> adj = superdsm.atoms.AtomAdjacencyGraph(atoms, clusters, fg_mask, seeds, 'muted') >>> adj.atom_labels frozenset({1, 2, 3, 4})
- property cluster_labels
The set of labels of all regions of possibly clustered objects.
>>> import superdsm.atoms >>> import numpy as np >>> atoms = np.array([[1, 1, 2, 4], ... [1, 3, 2, 4], ... [3, 3, 3, 4]]) >>> clusters = np.array([[1, 1, 2, 2], ... [1, 2, 2, 2], ... [2, 2, 2, 2]]) >>> fg_mask = np.ones(atoms.shape, bool) >>> seeds = [(0, 0), (0, 2), (2, 1), (1, 3)] >>> adj = superdsm.atoms.AtomAdjacencyGraph(atoms, clusters, fg_mask, seeds, 'muted') >>> adj.cluster_labels frozenset({1, 2})
- get_atom_degree(atom_label)
Returns the number of adjacent atomic image regions.
>>> import superdsm.atoms >>> import numpy as np >>> atoms = np.array([[1, 1, 2, 4], ... [1, 3, 2, 4], ... [3, 3, 3, 4]]) >>> clusters = np.array([[1, 1, 2, 2], ... [1, 2, 2, 2], ... [2, 2, 2, 2]]) >>> fg_mask = np.array([[True, False, True, False], ... [True, False, True, True], ... [True, True, True, True]]) >>> seeds = [(0, 0), (0, 2), (2, 1), (1, 3)] >>> adj = superdsm.atoms.AtomAdjacencyGraph(atoms, clusters, fg_mask, seeds, 'muted') >>> adj.get_atom_degree(1) 0 >>> adj.get_atom_degree(2) 2 >>> adj.get_atom_degree(3) 2 >>> adj.get_atom_degree(4) 2
- get_atoms_in_cluster(cluster_label)
Returns the set of labels of all atomic image regions, which are part of a region of possibly clustered objects.
>>> import superdsm.atoms >>> import numpy as np >>> atoms = np.array([[1, 1, 2, 4], ... [1, 3, 2, 4], ... [3, 3, 3, 4]]) >>> clusters = np.array([[1, 1, 2, 2], ... [1, 2, 2, 2], ... [2, 2, 2, 2]]) >>> fg_mask = np.ones(atoms.shape, bool) >>> seeds = [(0, 0), (0, 2), (2, 1), (1, 3)] >>> adj = superdsm.atoms.AtomAdjacencyGraph(atoms, clusters, fg_mask, seeds, 'muted') >>> adj.get_atoms_in_cluster(1) {1} >>> adj.get_atoms_in_cluster(2) {2, 3, 4}
- get_cluster_label(atom_label)
Returns the label of the region of possibly clustered objects, which an atomic image region is a part of.
>>> import superdsm.atoms >>> import numpy as np >>> atoms = np.array([[1, 1, 2, 4], ... [1, 3, 2, 4], ... [3, 3, 3, 4]]) >>> clusters = np.array([[1, 1, 2, 2], ... [1, 2, 2, 2], ... [2, 2, 2, 2]]) >>> fg_mask = np.ones(atoms.shape, bool) >>> seeds = [(0, 0), (0, 2), (2, 1), (1, 3)] >>> adj = superdsm.atoms.AtomAdjacencyGraph(atoms, clusters, fg_mask, seeds, 'muted') >>> adj.get_cluster_label(1) 1 >>> adj.get_cluster_label(2) 2 >>> adj.get_cluster_label(3) 2 >>> adj.get_cluster_label(4) 2
- get_edge_lines(accept='all', reduce=True)
Returns a list of lines corresponding to the edges of the graph.
- Parameters:
accept – Must be either
all
or a callable. Ifall
is used, all edges of the graph are included. Otherwise, an edge(i,j)
is included only ifaccept(i)
andaccept(j)
evaluate toTrue
, wherei
andj
are the labels of two adjacent atomic image regions.reduce – If
True
, then an edge(i,j)
is included only ifi > j
. Otherwise, both edges(i,j)
and(j,i)
are included.
Each line is a tuple of two seed points, and each seed point is a tuple of coordinates.
>>> import superdsm.atoms >>> import numpy as np >>> atoms = np.array([[1, 1, 2, 4], ... [1, 3, 2, 4], ... [3, 3, 3, 4]]) >>> clusters = np.array([[1, 1, 2, 2], ... [1, 2, 2, 2], ... [2, 2, 2, 2]]) >>> fg_mask = np.array([[True, False, True, False], ... [True, False, True, True], ... [True, True, True, True]]) >>> seeds = [(0, 0), (0, 2), (2, 1), (1, 3)] >>> adj = superdsm.atoms.AtomAdjacencyGraph(atoms, clusters, fg_mask, seeds, 'muted') >>> adj.get_edge_lines() [((0, 2), (2, 1)), ((0, 2), (1, 3)), ((2, 1), (1, 3))] >>> adj.get_edge_lines(lambda i: i != 4) [((0, 2), (2, 1))] >>> adj.get_edge_lines(lambda i: i != 4, reduce=False) [((0, 2), (2, 1)), ((2, 1), (0, 2))]
- get_seed(atom_label)
Returns the seed point which was used to determine an atomic image region.
- Returns:
Tuple of the coordinates of the seed point.
>>> import superdsm.atoms >>> import numpy as np >>> atoms = np.array([[1, 1, 2, 4], ... [1, 3, 2, 4], ... [3, 3, 3, 4]]) >>> clusters = np.array([[1, 1, 2, 2], ... [1, 2, 2, 2], ... [2, 2, 2, 2]]) >>> fg_mask = np.ones(atoms.shape, bool) >>> seeds = [(0, 0), (0, 2), (2, 1), (1, 3)] >>> adj = superdsm.atoms.AtomAdjacencyGraph(atoms, clusters, fg_mask, seeds, 'muted') >>> adj.get_seed(1) (0, 0) >>> adj.get_seed(2) (0, 2) >>> adj.get_seed(3) (2, 1) >>> adj.get_seed(4) (1, 3)
- property max_degree
The maximum degree of the graph.
>>> import superdsm.atoms >>> import numpy as np >>> atoms = np.array([[1, 1, 2, 4], ... [1, 3, 2, 4], ... [3, 3, 3, 4]]) >>> clusters = np.array([[1, 1, 2, 2], ... [1, 2, 2, 2], ... [2, 2, 2, 2]]) >>> fg_mask = np.array([[True, False, True, False], ... [True, False, True, True], ... [True, True, True, True]]) >>> seeds = [(0, 0), (0, 2), (2, 1), (1, 3)] >>> adj = superdsm.atoms.AtomAdjacencyGraph(atoms, clusters, fg_mask, seeds, 'muted') >>> adj.max_degree 2