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
[17:44:33] 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/fb173137f4a10a2e716974edf85b5bd0bfdaabbdad136111eafb54fd5d7e9b35.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/cfc9f0a457fdefc7d1003276afac63cee49040a2db6f888a6668ba110fd9615d.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/adc89aa0ecfd3aca0891afc915bcfa33f28a8d5bd32cff0707107a8eb2b63cf0.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/fee5d719957c7f7391768ede3879ddb59ff5efed9ab3429a6ae84e85ddc3f5fa.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/feccda3abb0cdd7b42ebfc50a82fcc37cb224821cec6980a547f74bf539219c5.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/5cec3862f2f39002e0d645a9e7b7fe456c303e4122ba7304e6e4354c880b1c55.png

Reproducing Images#

The random is controlled by numpy’s random number generator so the same image can be produced by setting the seed:

np.random.seed(0)
im1 = ps.generators.blobs(shape=[500, 500], porosity=0.5)
np.random.seed(0)
im2 = ps.generators.blobs(shape=[500, 500], porosity=0.5)
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/4c15972e12629e4aa8683229742e2e822f2af544393911c06da2edddcf3b152e.png