voronoi_edges#

import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
import inspect
b = inspect.signature(ps.generators.voronoi_edges)
print(b)
(shape: List[int], ncells: int, r: int = 0, flat_faces: bool = True)

shape#

The image can be 2D and 3D

shape = [100, 100]
ncells = 20
im = ps.generators.voronoi_edges(shape=shape, ncells=ncells)
fig, ax = plt.subplots(figsize=[4, 4])
ax.imshow(im, origin='lower', interpolation='none')
ax.axis(False);
../../../_images/971ca045d51b1a583fd44d00e897c55ef6c904b2e1aa56216fe5ef3af9e4e4ed.png
shape = [50, 50, 50]
ncells = 40
im = ps.generators.voronoi_edges(shape=shape, r=3, ncells=ncells)
fig, ax = plt.subplots(figsize=[4, 4])
ax.imshow(ps.visualization.show_3D(im), interpolation='none')
ax.axis(False);
../../../_images/7f850faec5931843850603435e12d638d354061c7ae76c836fe6d8ff789911b1.png

flat_faces#

By default the image will have voronoi edges laying on the image faces. This is accomplished by reflecting the points along each axis before running the tessellation. This can be disabled by setting flat_faces=False, but note that edges pointing to infinity are not drawn.

shape = [100, 100]
flat_faces = False
im = ps.generators.voronoi_edges(shape=shape, ncells=ncells, flat_faces=flat_faces)
fig, ax = plt.subplots(figsize=[4, 4])
ax.imshow(im, origin='lower', interpolation='none')
ax.axis(False);
../../../_images/dfb73da05af5c307b181128a05f31d7b685e9b73d5204dcc00c54f66370d9622.png

r radius#

The thickness of the edges. By default they are 1 pixel thick, but can be made fatter by setting r > 0.

fig, ax = plt.subplots(1, 2, figsize=[8, 4])

r = 1
ncells = 10
im1 = ps.generators.voronoi_edges(shape=shape, r=r, ncells=ncells)
ax[0].imshow(im1, origin='lower', interpolation='none')
ax[0].set_title(f'r = {r}')
ax[0].axis(False)

r = 4
im2 = ps.generators.voronoi_edges(shape=shape, r=r, ncells=ncells)
ax[1].imshow(im2, origin='lower', interpolation='none')
ax[1].set_title(f'r = {r}')
ax[1].axis(False);
../../../_images/eb3b2e1c067bb0b9717ac4cfc8af9fff371e942569e86dd0327e69752e30fb92.png

ncells#

The number of Voronoi cells to add

fig, ax = plt.subplots(1, 2, figsize=[8, 4])

ncells = 10
im1 = ps.generators.voronoi_edges(shape=shape, ncells=ncells)
ax[0].imshow(im1, origin='lower', interpolation='none')
ax[0].set_title(f'ncells = {ncells}')
ax[0].axis(False)

ncells = 40
im2 = ps.generators.voronoi_edges(shape=shape, ncells=ncells)
ax[1].imshow(im2, origin='lower', interpolation='none')
ax[1].set_title(f'ncells = {ncells}')
ax[1].axis(False);
../../../_images/58a23aa3df4e58ebf1cb63973ae69bcfd0024831052884e8b43f13cce464c8d8.png