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

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/35a965eeee72798e65c3bd4eda6db1ef99025bdbdbcbd3be3c604eb94f6cb23d.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/878f8217ba0012f0330008339bea62f41804cc140e70f8e4a0100365e96215e6.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/e34dc299282d7599befcea14dbdbe576954ed966e6d455f31497f5ae913f8587.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/78ba8eadb94dd87c92854f10e1fbff8e2966e7ee7fe7a29fbaf4d27dc4f247dd.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/c56cc8c3f8b211a461c3f71abb52d7c7f31e984edb3a1d724d856bf48d6da138.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/0b5eca66b12dbbd7ee0470ce143bb55f0e38dd629749033a657c863f15daec45.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/ce1586c07c3c84db933bd1af7f1d56ce9490a271fe83fd6606c17ab5797c35db.png