dijkstra_segmentation
actugraph Link
actugraph(G)
Calculates the weight of graph edges based on the commute-time distance using eigenvalues and eigenvectors of the graph Laplacian matrix.
This function computes the Laplacian matrix of the graph, calculates its eigenvalues and eigenvectors, and updates the weights of the edges in the graph using the commute-time distance. The commute-time distance is derived from the eigenvectors and eigenvalues of the Laplacian matrix.
Parameters:
-
G
(Graph
) –The input graph on which computations will be performed. The graph can have weighted or unweighted edges, and it will be updated with new weights based on the computed commute-time distances.
Returns:
-
Graph
–A modified version of the input graph with updated edge weights. Each edge weight represents the commute-time distance between its endpoints.
Raises:
-
TypeError
–If the input
G
is not anetworkx.Graph
.
Source code in spectral_clustering/dijkstra_segmentation.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
affichesegm Link
affichesegm(pcd, segmentdict, c)
Visualizes intermediate results, specifically line segments.
This function builds a graph representation of the segments and visualizes the graph along with the original point cloud.
Parameters:
-
pcd
(PointCloud
) –The input point cloud to which the segments belong.
-
segmentdict
(dict
) –A dictionary where keys are segment indices and values are lists of indices representing the line segments in the graph.
-
c
(int
) –The number of distinct segments in the graph.
Notes
This function uses Open3D to render point clouds and geometry and uses NetworkX to build the graph based on the segment information. Line segments are visualized along with the point cloud based on the provided input.
Source code in spectral_clustering/dijkstra_segmentation.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
|
densiftige Link
densiftige(G, segmsource, ptsource, ptarrivee, pathsupp=5)
Densifies a segment of the given graph by adding alternate shorter paths between the source and target nodes.
This method focuses on minimizing the error of misclassifying points belonging to the segment as those in branches, potentially reducing inconsistencies in the graph representation.
Parameters:
-
G
(Graph
) –The input graph representing the network structure.
-
segmsource
(list
) –The main segment to be densified, represented as a list of nodes forming the segment in the graph.
-
ptsource
(any
) –The starting node for the segment in the graph.
-
ptarrivee
(any
) –The target node for the segment in the graph.
-
pathsupp
(int
, default:5
) –The number of additional shorter paths to compute and densify the segment with, by default 5.
Returns:
-
list
–The updated segment with added shorter paths forming a densified structure.
Source code in spectral_clustering/dijkstra_segmentation.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
initdijkstra Link
initdijkstra(G)
Initializes the first segment of the graph using Dijkstra's algorithm.
This function randomly selects a starting node from the graph, computes the shortest path distances from the selected node to all other nodes, and determines the farthest endpoint based on these distances. It then repeats the process starting from the farthest endpoint to determine another distant endpoint. Finally, it computes the shortest path between the two farthest endpoints and returns the path along with the source and destination nodes.
Parameters:
-
G
(Graph
) –A graph representation, where nodes are connected by weighted edges.
Returns:
-
list
–The shortest path (as a sequence of nodes) between the final source and destination nodes with maximum distance calculated using Dijkstra's algorithm.
-
int or str
–The node corresponding to the starting point (farthest from the randomly chosen node initially).
-
int or str
–The node corresponding to the endpoint (farthest from the source node).
Source code in spectral_clustering/dijkstra_segmentation.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
initdijkstralitt Link
initdijkstralitt(G)
Initializes the first segment in a graph using Dijkstra's algorithm.
This function selects a random node from the graph and computes a segment (based on shortest paths and their lengths) between two nodes. Specifically, it identifies the two most distant nodes from each other in terms of shortest path weights and determines a direct path connecting them.
Parameters:
-
G
(Graph
) –A graph represented as a NetworkX graph instance. The graph's edges must have a "weight" attribute to compute shortest path weights.
Returns:
-
list
–A list of nodes representing the shortest path (based on edge weights) between two most distant nodes in the graph.
Source code in spectral_clustering/dijkstra_segmentation.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
segmdijkstra Link
segmdijkstra(G, segmsource, prop=0.25)
Calculates the segmentation of a network graph using an iterative approach based on Dijkstra's algorithm and evaluates the connectivity of graph nodes. The function returns the dictionary of path segments and the count of segments before the stopping condition is met.
Parameters:
-
G
(Graph
) –The input graph on which the segmentation is performed. The graph should be weighted, with weights specified via the 'weight' attribute on edges.
-
segmsource
(list
) –A list specifying the source nodes from which the segmentation paths are initialized.
-
prop
(float
, default:0.25
) –A propagation threshold value used to determine the stopping condition of the segmentation process. The default value is 0.25.
Returns:
-
dict
–A dictionary where keys are the segment numbers, and values are lists of nodes that form the paths for each segment.
-
int
–The total number of segments that were created before the stopping condition was satisfied.
Source code in spectral_clustering/dijkstra_segmentation.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
segmdijkstralitt Link
segmdijkstralitt(G, segmsource, c)
Compute segmented paths within a graph using Dijkstra's shortest path algorithm.
This function iteratively calculates segmented paths within the given graph. At each step, it identifies a new segment based on the longest weighted path from a multi-source Dijkstra's search on the graph, starting from the combined set of nodes in already identified segments. The function also updates and reorganizes existing segments to account for the newly identified segment.
Parameters:
-
G
(Graph
) –The graph on which the segmented Dijkstra algorithm will be applied. The graph must have a 'weight' attribute defined for its edges.
-
segmsource
(list
) –A list of nodes representing the source segment(s) within the graph. Initial segments for the segmentation process.
-
c
(int
) –The number of iterations to perform, which defines the level of segmentation.
Returns:
-
dict
–A dictionary where keys are segment ids (integers starting from 1) and values are lists of nodes representing the segments identified at each iteration.
Source code in spectral_clustering/dijkstra_segmentation.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
sortienuagesegm Link
sortienuagesegm(pcd, G, segmentdict, c)
Sorts points in a point cloud based on their shortest paths in a graph, assigns labels to them, and saves the results to a file.
The function assigns a classification label to each point in a given
point cloud based on the shortest path distances computed from a set
of initial segments within a graph. Labels are determined by the segments
the points are closest to. If a point cannot be classified, it is assigned
a default label c
. The resulting labeled point cloud is saved as a text
file.
Parameters:
-
pcd
(PointCloud
) –The input point cloud object, which contains the 3D points to be classified.
-
G
(Graph
) –A graph where the shortest paths are computed. Nodes represent points, and edges have weights indicating distances.
-
segmentdict
(dict
) –A dictionary representing segments. Keys are integers, and values are lists of integers representing node indices in the graph, which define segments considered for classification.
-
c
(int
) –The default class label assigned to points that cannot be associated with any segment.
Notes
The function modifies the point labels by computing the shortest path from a set of segments in the graph to every point in the point cloud. For points that belong to more than one segment, it labels them based on their closest segment sequence in the search process.
The labeled point cloud is saved as a comma-separated text file named 'pcdclassifdijkstra3.txt'. The result includes the 3D coordinates of points and their corresponding labels.
This function assumes that no duplicate edges with differing weights exist in the graph and that the provided point cloud is valid with a consistent structure.
Source code in spectral_clustering/dijkstra_segmentation.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
|