Obtain edges of a 1D, 2D, or 3D graph based on the neighbourhood structure.
getEdges(mask, neiStruc)
mask | a vector, matrix, or 3D array specifying vertices of a graph. Vertices of value 1 are within the graph and 0 are not. |
---|---|
neiStruc | a scalar, vector of four components, or \(3\times4\) matrix corresponding to 1D, 2D, or 3D graphs. It specifies the neighbourhood structure. See |
A matrix of two columns with one edge per row. The edges connecting
vertices and their corresponding first neighbours are listed first, and
then those corresponding to the second neighbours, and so on and so
forth. The order of neighbours is the same as in getNeighbors
.
There could be more than one way to define the same 3D neighbourhood structure for a graph (see Example 4 for illustration).
Winkler, G. (2003) "Image Analysis, Random Fields and Markov Chain Monte Carlo Methods: A Mathematical Introduction" (2nd ed.) Springer-Verlag
Feng, D. (2008) "Bayesian Hidden Markov Normal Mixture Models with Application to MRI Tissue Classification" Ph. D. Dissertation, The University of Iowa
#Example 1: get all edges of a 1D graph. mask <- c(0,0,rep(1,4),0,1,1,0,0) getEdges(mask, neiStruc=2)#> [,1] [,2] #> [1,] 1 2 #> [2,] 2 3 #> [3,] 3 4 #> [4,] 5 6#Example 2: get all edges of a 2D graph based on neighbourhood structure # corresponding to the first-order Markov random field. mask <- matrix(1 ,nrow=2, ncol=3) getEdges(mask, neiStruc=c(2,2,0,0))#> [,1] [,2] #> [1,] 1 2 #> [2,] 3 4 #> [3,] 5 6 #> [4,] 1 3 #> [5,] 2 4 #> [6,] 3 5 #> [7,] 4 6#Example 3: get all edges of a 2D graph based on neighbourhood structure # corresponding to the second-order Markov random field. mask <- matrix(1 ,nrow=3, ncol=3) getEdges(mask, neiStruc=c(2,2,2,2))#> [,1] [,2] #> [1,] 1 2 #> [2,] 2 3 #> [3,] 4 5 #> [4,] 5 6 #> [5,] 7 8 #> [6,] 8 9 #> [7,] 1 4 #> [8,] 2 5 #> [9,] 3 6 #> [10,] 4 7 #> [11,] 5 8 #> [12,] 6 9 #> [13,] 1 5 #> [14,] 2 6 #> [15,] 4 8 #> [16,] 5 9 #> [17,] 2 4 #> [18,] 3 5 #> [19,] 5 7 #> [20,] 6 8#Example 4: get all edges of a 3D graph based on 6 neighbours structure # where the neighbours of a vertex comprise its available # N,S,E,W, upper and lower adjacencies. To achieve it, there # are several ways, including the two below. mask <- array(1, dim=rep(3,3)) n61 <- matrix(c(2,2,0,0, 0,2,0,0, 0,0,0,0), nrow=3, byrow=TRUE) n62 <- matrix(c(2,0,0,0, 0,2,0,0, 2,0,0,0), nrow=3, byrow=TRUE) e1 <- getEdges(mask, neiStruc=n61) e2 <- getEdges(mask, neiStruc=n62) e1 <- e1[order(e1[,1], e1[,2]),] e2 <- e2[order(e2[,1], e2[,2]),] all(e1==e2)#> [1] TRUE#Example 5: get all edges of a 3D graph based on 18 neighbours structure # where the neighbours of a vertex comprise its available # adjacencies sharing the same edges or faces. # To achieve it, there are several ways, including the one below. n18 <- matrix(c(2,2,2,2, 0,2,2,2, 0,0,2,2), nrow=3, byrow=TRUE) mask <- array(1, dim=rep(3,3)) getEdges(mask, neiStruc=n18)#> [,1] [,2] #> [1,] 1 2 #> [2,] 2 3 #> [3,] 4 5 #> [4,] 5 6 #> [5,] 7 8 #> [6,] 8 9 #> [7,] 10 11 #> [8,] 11 12 #> [9,] 13 14 #> [10,] 14 15 #> [11,] 16 17 #> [12,] 17 18 #> [13,] 19 20 #> [14,] 20 21 #> [15,] 22 23 #> [16,] 23 24 #> [17,] 25 26 #> [18,] 26 27 #> [19,] 1 4 #> [20,] 2 5 #> [21,] 3 6 #> [22,] 4 7 #> [23,] 5 8 #> [24,] 6 9 #> [25,] 10 13 #> [26,] 11 14 #> [27,] 12 15 #> [28,] 13 16 #> [29,] 14 17 #> [30,] 15 18 #> [31,] 19 22 #> [32,] 20 23 #> [33,] 21 24 #> [34,] 22 25 #> [35,] 23 26 #> [36,] 24 27 #> [37,] 1 5 #> [38,] 2 6 #> [39,] 4 8 #> [40,] 5 9 #> [41,] 10 14 #> [42,] 11 15 #> [43,] 13 17 #> [44,] 14 18 #> [45,] 19 23 #> [46,] 20 24 #> [47,] 22 26 #> [48,] 23 27 #> [49,] 2 4 #> [50,] 3 5 #> [51,] 5 7 #> [52,] 6 8 #> [53,] 11 13 #> [54,] 12 14 #> [55,] 14 16 #> [56,] 15 17 #> [57,] 20 22 #> [58,] 21 23 #> [59,] 23 25 #> [60,] 24 26 #> [61,] 1 10 #> [62,] 2 11 #> [63,] 3 12 #> [64,] 4 13 #> [65,] 5 14 #> [66,] 6 15 #> [67,] 7 16 #> [68,] 8 17 #> [69,] 9 18 #> [70,] 10 19 #> [71,] 11 20 #> [72,] 12 21 #> [73,] 13 22 #> [74,] 14 23 #> [75,] 15 24 #> [76,] 16 25 #> [77,] 17 26 #> [78,] 18 27 #> [79,] 1 11 #> [80,] 2 12 #> [81,] 4 14 #> [82,] 5 15 #> [83,] 7 17 #> [84,] 8 18 #> [85,] 10 20 #> [86,] 11 21 #> [87,] 13 23 #> [88,] 14 24 #> [89,] 16 26 #> [90,] 17 27 #> [91,] 2 10 #> [92,] 3 11 #> [93,] 5 13 #> [94,] 6 14 #> [95,] 8 16 #> [96,] 9 17 #> [97,] 11 19 #> [98,] 12 20 #> [99,] 14 22 #> [100,] 15 23 #> [101,] 17 25 #> [102,] 18 26 #> [103,] 1 13 #> [104,] 2 14 #> [105,] 3 15 #> [106,] 4 16 #> [107,] 5 17 #> [108,] 6 18 #> [109,] 10 22 #> [110,] 11 23 #> [111,] 12 24 #> [112,] 13 25 #> [113,] 14 26 #> [114,] 15 27 #> [115,] 4 10 #> [116,] 5 11 #> [117,] 6 12 #> [118,] 7 13 #> [119,] 8 14 #> [120,] 9 15 #> [121,] 13 19 #> [122,] 14 20 #> [123,] 15 21 #> [124,] 16 22 #> [125,] 17 23 #> [126,] 18 24