boxcount#

A method for measuring the fractal dimension of an image

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

The arguments and their defaults for this function are:

import inspect
inspect.signature(ps.metrics.boxcount)
<Signature (im, bins=10)>
im = ps.generators.sierpinski_foam(dmin=5, n=5, ndim=2)
fig, ax = plt.subplots(1, 1, figsize=[6, 6])
ax.imshow(im, interpolation='none', origin='lower')
ax.axis(False);
../../../_images/64a100a3c4b3152cdf1656199271d4f5dbe9f71bcd46fde6732462c13a8f338d.png

im#

The image which is to be analzyed. Can be 2D or 3D.

b = ps.metrics.boxcount(im=im)
print(b)
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
Results of boxcount generated at Wed Oct 25 12:40:13 2023
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
size                      Array of size (10,)
count                     [6505, 4095, 1435, 552, 206, 77, 24, 9, 4, 1]
slope                     Array of size (10,)
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

The returned object is like a dataclass with each computed value stored in an attribute. The result can be printed for inspection. The results can also be plotted as follows:

fig, ax = plt.subplots(1, 2, figsize=[12, 6])
ax[0].loglog(b.size, b.count)
ax[0].set_xlabel('box length')
ax[0].set_ylabel('number of partially filled boxes')

ax[1].semilogx(b.size, b.slope)
ax[1].plot([0, 1000], [1.9, 1.9])
ax[1].set_xlabel('box length')
ax[1].set_ylabel('slope')
ax[1].set_ylim([0, 3]);
../../../_images/8a5bdc40de5979c4f4a556f7716b0a88a1fe5f240b6f5c01dfe2a1889a1adb6c.png

bins#

The box sizes to use. The default is 10. If an integer is given it computes the range of box sizes. If an array is given, these are used directly

b = ps.metrics.boxcount(im=im, bins=20)
fig, ax = plt.subplots(1, 2, figsize=[12, 6])
ax[0].loglog(b.size, b.count)
ax[0].set_xlabel('box length')
ax[0].set_ylabel('number of partially filled boxes')

ax[1].semilogx(b.size, b.slope)
ax[1].plot([0, 1000], [1.9, 1.9])
ax[1].set_xlabel('box length')
ax[1].set_ylabel('slope')
ax[1].set_ylim([0, 3]);
../../../_images/12c4744559e5f0a446784b2afa44d9fb2d77160e012a62f66d7ec3caa03cb27c.png