blobs

blobs is a simple function to generate a test image. It works by generating random noise, applying a guassian blur, renormalizing the result back to a uniform distribution, then thresholding the result to produce a binary image.

import porespy as ps
import matplotlib.pyplot as plt
import numpy as np
[18:50:47] ERROR    PARDISO solver not installed, run `pip install pypardiso`. Otherwise,          _workspace.py:56
                    simulations will be slow. Apple M chips not supported.                                         

shape

Both 2D and 3D images can be generated. Sending a scalar (shape=100) will produce a 3D image of size 100^3.

shape = [200, 200]
im = ps.generators.blobs(shape=shape)
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.imshow(im, origin='lower', interpolation='none')
ax.axis(False);
../../../_images/718b4e9770d1038a9bcb26bc17ed9d05839efcdf8dda26ae5c4bb69b4f18166d.png

porosity

The fraction of the True to False pores can be set by specifying the porosity. The default is 0.5.

e = 0.75
im = ps.generators.blobs(shape=[500, 500], porosity=e)
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.imshow(im, origin='lower', interpolation='none')
ax.axis(False);
../../../_images/d6ca62b16847d0af1601771d8d6cebcc044effd1dd6f9b51726505de81005b62.png

Specifying porosity=None will return a greyscale image which can then be thresholded to get a boolean image. The greyscale value are adjusted to a unifrom distribution:

im = ps.generators.blobs(shape=[500, 500], porosity=None)
fig, ax = plt.subplots(1, 2, figsize=[8, 4])

ax[0].imshow(im, origin='lower', interpolation='none')
ax[0].axis(False)

ax[1].hist(im.flatten(), edgecolor='k');
../../../_images/4728a172d5cccc6e32ef7b406bc5d866554ec9fb2a12386491c1838c10aa3512.png
im = ps.generators.blobs(shape=[500, 500], porosity=None, blobiness=1)
fig, ax = plt.subplots(1, 3, figsize=[12, 4])
ax[0].imshow(im, origin='lower', interpolation='none')
ax[0].axis(False)
ax[1].imshow(im < 0.5, origin='lower', interpolation='none')
ax[1].axis(False)
ax[2].imshow(im < 0.75, origin='lower', interpolation='none')
ax[2].axis(False);
../../../_images/e28a1a84b1297d74408a719a6d14624bad29d80f15e7c4378de84299301eb857.png

blobiness

The size and anisotropy of the blobs can be changed:

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

im1 = ps.generators.blobs(shape=shape, porosity=e, blobiness=1)
ax[0].imshow(im1, origin='lower', interpolation='none')
ax[0].axis(False)

im2 = ps.generators.blobs(shape=shape, porosity=e, blobiness=2)
ax[1].imshow(im2, origin='lower', interpolation='none')
ax[1].axis(False);
../../../_images/b0088cbf8e11ec448fb79cdd712a7ed2fa7d14b75c7153419892ce96664b060b.png
fig, ax = plt.subplots(1, 2, figsize=[8, 4])

im1 = ps.generators.blobs(shape=shape, porosity=e, blobiness=[2, 1])
ax[0].imshow(im1, origin='lower', interpolation='none')
ax[0].axis(False)

im2 = ps.generators.blobs(shape=shape, porosity=e, blobiness=[1, 3])
ax[1].imshow(im2, origin='lower', interpolation='none')
ax[1].axis(False);
../../../_images/0757622770576bf19ee5b541b6aff3e3405c61edde28043ff1b2b902702d40cd.png

seed

It is possible to get the same image by passing an integer to the seed argument. This sets the numpy random number generator the specified initial state.

im1 = ps.generators.blobs(shape=[500, 500], porosity=0.5, seed=0)
im2 = ps.generators.blobs(shape=[500, 500], porosity=0.5, seed=0)
fig, ax = plt.subplots(1, 2, figsize=[8, 4])
ax[0].imshow(im1, origin='lower', interpolation='none')
ax[0].axis(False)
ax[1].imshow(im2, origin='lower', interpolation='none')
ax[1].axis(False);
../../../_images/f101bb9a7f11db6574fd5276df26262ed554707a72ae7940afb9f0eabe62f84f.png

periodic

It is sometimes desirable to create an image with periodic boundaries such that the right edge matches the left edge. This allows the image to be tiled while maintaining connectivity of the void space.

im = ps.generators.blobs(shape=[500, 500], porosity=0.5, seed=0, periodic=True)
im2 = np.tile(im, [2, 2])

fig, ax = plt.subplots(1, 2)
ax[0].imshow(im, interpolation='none')
ax[0].axis(False)
ax[1].imshow(im2, interpolation='none')
ax[1].axis(False)
(-0.5, 999.5, 999.5, -0.5)
../../../_images/9143f6b80aee226a6021f08b93df1686e950928070d7d60f69822bad103f0122.png