grains.cad.splinegonize¶
-
grains.cad.splinegonize(label_image, neighbor_search_algorithm, connectivity=1, detect_boundaries=True, degree_min=3, degree_max=8, continuity='C2', tol=0.0001)[source]¶ Polygon representation of a label image.
- Parameters
label_image (ndarray) – Labeled input image, represented as a 2D numpy array of positive integers.
neighbor_search_algorithm (functools.partial) – Specifies which algorithm to use for constructing the branch-region connectivity. The function to be passed (along with its arguments) is
skeleton2regions().connectivity ({1,2}, optional) – A connectivity of 1 (default) means pixels sharing an edge will be considered neighbors. A connectivity of 2 means pixels sharing a corner will be considered neighbors.
detect_boundaries (bool, optional) – When True, the image boundaries will be treated as part of the skeleton. This allows identifying boundary regions in the skeleton2regions function. The default is True.
- Other Parameters
degree_min, degree_max, continuity, tol – See the
fit_spline()function.- Returns
splinegons (dict) – The keys in the dictionary correspond to the labels of the input image, while the values are TopoDS_Face objects, the surfaces of the regions.
boundaries (dict) – The keys in the dictionary correspond to the labels of the input image, while the values are TopoDS_Wire objects, the boundaries of the regions.
Examples
>>> test_image = np.array([ ... [1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3], ... [2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3], ... [2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], ... [2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]], ... dtype=np.int8) >>> splinegons, _ = splinegonize(test_image, search_neighbor(2, np.inf), connectivity=1, tol=0.1) >>> plot_splinegons(list(splinegons.values()))