similarity_graph
add_label_from_pcd_file Link
add_label_from_pcd_file(G, file='Data/peuplier_seg.txt')
Assigns clustering labels to a graph G
from a specified Point Cloud Data (PCD) file.
The function reads a given file containing point cloud data where clustering labels are
extracted from the fourth column (index 3) of the file data. These labels are set as a new
attribute clustering_labels
of the graph G
and are also assigned to individual nodes
within the graph. This assignment links clustering information from the point cloud data
to the graph structure.
Parameters:
-
G
(Graph
) –A graph representation of the dataset where each node will be assigned a clustering label based on the point cloud data loaded from the input file.
-
file
(str
, default:'Data/peuplier_seg.txt'
) –File path to the PCD (Point Cloud Data) file in text format. By default, the path points to a specific
.txt
dataset: "/Users/katiamirande/PycharmProjects/ Spectral_clustering_0/Data/peuplier_seg.txt".
Notes
The function expects that the input data in the provided file contains at least four columns, where the fourth column (index 3) corresponds to the clustering labels. The labels are expected to be integers. The function specifically reshapes these labels before assigning them to the graph.
Source code in spectral_clustering/similarity_graph.py
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 |
|
add_label_from_separate_file Link
add_label_from_separate_file(G, file='Data/rawLabels_Arabido_0029.txt')
Adds clustering labels from a separate file to the graph G
.
This function reads a file containing clustering labels, processes it into an integer array, and assigns these labels both as a graph-level attribute and node-level attributes. The labels for nodes are assigned sequentially based on the order of nodes in the graph.
Parameters:
-
G
(Graph
) –The graph to which clustering labels will be assigned.
-
file
(str
, default:'Data/rawLabels_Arabido_0029.txt'
) –Path to the file containing clustering labels. The file is expected to contain comma-separated values. Defaults to " Data/rawLabels_Arabido_0029.txt".
Notes
- The labels in the file are expected to align with the order of nodes in the
graph
G
. - The clustering labels are stored as an attribute for the graph (
clustering_labels
) and as an attribute for each node (G.nodes[n]['clustering_labels']
).
Source code in spectral_clustering/similarity_graph.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
create_connected_riemannian_graph Link
create_connected_riemannian_graph(point_cloud, method='knn', nearest_neighbors=1, radius=1.0)
Create a connected Riemannian graph from a point cloud using a specified method.
This function takes a point cloud and generates a Riemannian graph based on the provided method and parameters. If the generated graph is not connected, it extracts the largest connected component from the graph, saves the corresponding points, and regenerates the graph. The final graph and updated point cloud are returned.
Parameters:
-
point_cloud
(PointCloud
) –Input point cloud data.
-
method
(str
, default:'knn'
) –Method to generate the Riemannian graph. Options are 'knn' (k-nearest neighbors) or other methods, by default 'knn'.
-
nearest_neighbors
(int
, default:1
) –Number of nearest neighbors to use when creating the graph (if method is 'knn'), by default 1.
-
radius
(float
, default:1.0
) –Radius parameter to define connectivity (if applicable to the method), by default 1.0.
Returns:
-
Graph
–The connected Riemannian graph.
-
PointCloud
–The updated point cloud corresponding to the connected graph.
Source code in spectral_clustering/similarity_graph.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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
create_riemannian_graph Link
create_riemannian_graph(pcd, method='knn', nearest_neighbors=1, radius=1.0)
Generate a similarity graph from a point cloud.
Parameters:
-
p
(PointCloud
) –Point cloud on which to compute the similarity graph
-
method
(str
, default:'knn'
) –Search method : 'knn' or 'radius'
-
nearest_neighbors
(int
, default:1
) –Number of nearest neighbors for the 'knn' method
-
radius
(float
, default:1.0
) –Radius for the 'radius' method
Returns:
-
Graph
–Similarity graph computed on the point cloud
Source code in spectral_clustering/similarity_graph.py
13 14 15 16 17 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 |
|
draw_graph_cellcomplex Link
draw_graph_cellcomplex(pcd, G, pcd_to_superimpose)
Draws a graph cell complex visualization using the provided point cloud, graph and an additional point cloud for superimposition.
The function generates a 3D representation of the graph with edges and vertices colored and styled using predefined colormaps and glyph configurations, and displays it using VTK.
Parameters:
-
pcd
(PointCloud or ndarray
) –The primary point cloud used to define the coordinates of the graph vertices. It can either be an
o3d.geometry.PointCloud
object or a numpy array of point coordinates. -
G
(Graph
) –The input graph whose nodes and edges will be visualized. Nodes must correspond to elements in the
pcd
parameter, and edges define the connections to be drawn. -
pcd_to_superimpose
(PointCloud or ndarray
) –An additional point cloud that will be visualized as a superimposed set of points on the graph. This provides a way to compare or highlight a separate dataset in relation to the graph cell complex.
Source code in spectral_clustering/similarity_graph.py
221 222 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 268 269 270 271 272 273 274 275 276 277 278 |
|
draw_graph_open3d Link
draw_graph_open3d(pcd, G)
Visualize a graph overlaid on a 3D point cloud using o3d.
This function creates a line set object from the provided graph edges and associates it with the nodes represented by the points in the point cloud. The resulting visualization is displayed in an Open3D viewer to provide an interactive 3D representation of the graph.
Parameters:
-
pcd
(PointCloud
) –A 3D point cloud object where each point is treated as a node of the graph.
-
G
(Graph
) –A graph object, containing edges as tuples of integers representing connections between the indices of points in the provided point cloud.
Source code in spectral_clustering/similarity_graph.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
export_eigenvectors_on_pointcloud Link
export_eigenvectors_on_pointcloud(pcd, keigenvec, k, filename='vecteurproprecol.txt')
Export eigenvectors associated with a specific eigenvalue to a file for visualization alongside the point cloud data.
This function computes a new array combining the coordinates of the points in the point cloud and the eigenvectors corresponding to a specific eigenvalue. The combined data is then saved to a CSV file for potential visualization purposes, e.g., in a tool like CloudCompare.
Parameters:
-
pcd
(PointCloud
) –The input point cloud from which coordinates are extracted.
-
keigenvec
(ndarray
) –The matrix of eigenvectors where each column corresponds to an eigenvalue.
-
k
(int
) –The index of the eigenvalue whose eigenvectors will be used.
-
filename
(str
, default:'vecteurproprecol.txt'
) –The name of the output file where the combined data will be saved. Default is 'vecteurproprecol.txt'.
Source code in spectral_clustering/similarity_graph.py
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 |
|
export_pointcloud_on_eigenvectors_3d Link
export_pointcloud_on_eigenvectors_3d(keigenvec, vec1, vec2, vec3, filename='espacespec.txt')
Export a 3D point cloud using specific eigenvector indices.
This function extracts points from the given eigenvector matrix based on specified indices and exports the resulting 3D coordinates into a text file in a tabular format. The saved file consists of points where each row contains three values representing a single point in 3D space. The points are separated by commas for easier parsing.
Parameters:
-
keigenvec
(ndarray
) –A 2D array where each column represents an eigenvector and rows represent points in the dataset. It is expected to have at least three columns to extract 3D coordinates.
-
vec1
(int
) –Index of the eigenvector to use as the x-coordinate.
-
vec2
(int
) –Index of the eigenvector to use as the y-coordinate.
-
vec3
(int
) –Index of the eigenvector to use as the z-coordinate.
-
filename
(str
, default:'espacespec.txt'
) –The name of the file to save the output. The default is 'espacespec.txt', and the data in the file will be saved in a comma-separated value format.
Source code in spectral_clustering/similarity_graph.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|