porespy.beta.vor_to_im#

porespy.beta.vor_to_im(vor, im, centroids=True)#

Render a 2-D Voronoi tessellation onto a boolean image.

Traces each finite Voronoi ridge as a line of True voxels. Ridges that extend to infinity (vertex index -1) are skipped. Optionally the original seed points are also marked.

Parameters:
  • vor (scipy.spatial.Voronoi) – A Voronoi tessellation object, typically created with scipy.spatial.Voronoi.

  • im (ndarray) – A 2-D array used only to determine the output shape and dtype. Its values are ignored; the returned image is zero-initialised.

  • centroids (bool, optional) – If True (default), the seed points (vor.points) are marked as True in the output image in addition to the ridge lines.

Returns:

im – A 2-D boolean array with the same shape as the input im. Pixels on Voronoi ridges (and seed points, if centroids=True) are True; all other pixels are False.

Return type:

ndarray of bool

Notes

Infinite ridges (those with a vertex index of -1 in vor.ridge_vertices) are silently skipped. Ridge vertices that fall outside the image bounds are clipped at the boundary during line rasterisation.

Examples

>>> import numpy as np
>>> import scipy.spatial as sptl
>>> pts = np.random.rand(50, 2) * 200
>>> vor = sptl.Voronoi(pts)
>>> im = np.zeros([200, 200], dtype=bool)
>>> result = vor_to_im(vor, im)