porespy.beta.pts_to_voronoi#
- porespy.beta.pts_to_voronoi(im, r=0, centroids=True, borders=True)#
Compute a Voronoi tessellation from seed points via watershed.
Each
Truepixel inimis treated as a seed. An EDT-based watershed grows regions from those seeds to fill the domain. Optionally the seeds are iteratively relaxed to region centroids (Lloyd’s algorithm) before the final tessellation is returned.- Parameters:
im (ndarray of bool) – A 2-D boolean image where
Truepixels mark the Voronoi seed points.r (int, optional) – Number of Lloyd relaxation iterations. At each step the seeds are replaced by the centroids of the current Voronoi regions and the tessellation is recomputed.
r=0(default) uses the original seeds without relaxation.centroids (bool, optional) – If
True(default), the centroid of each final Voronoi region is marked with the value-1in the returned label image.borders (bool, optional) – If
True(default), watershed lines (the Voronoi boundaries) are included in the output as pixels with value0. IfFalse, every pixel is assigned to its nearest region and no boundary pixels exist.
- Returns:
ws – A 2-D integer label array the same shape as
im. Each Voronoi region carries a unique positive integer label. Boundary pixels are0(whenborders=True), and centroid pixels are-1(whencentroids=True).- Return type:
ndarray of int
Notes
The watershed is seeded from the labelled connected components of
imand grows into the distance-transform of~im. Each relaxation iteration replaces the current seeds with the centre-of-mass of every labelled region, then callspts_to_voronoirecursively withr=0.Examples
>>> import numpy as np >>> im = np.zeros([200, 200], dtype=bool) >>> pts = (np.random.rand(50, 2) * 200).astype(int) >>> im[pts[:, 0], pts[:, 1]] = True >>> ws = pts_to_voronoi(im, r=2)