pore_size_distribution

Calculates the pore size distribution in the image produced by either local thickness or porosimetry method where each voxel in the image shows the radius of the largest sphere (circle in 2D) that would overlap it.

import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
import inspect
inspect.signature(ps.metrics.pore_size_distribution)
<Signature (im, bins=10, log=True, voxel_size=1)>

im

The input image csontaining the sizes of the largest sphere that overlaps each voxel. This image can be generated by implementing porosimetry or local_thickness filter on a binary image. Let’s generate a test image:

np.random.seed(10)
im = ps.generators.blobs(shape=[500, 500])
im = ps.filters.porosimetry(im)
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.imshow(im, origin='lower', interpolation='none')
ax.axis(False);
../../../_images/394da113bc4c9ecce39a3d91e7ab966aaab39972cc48e7c573f9f3d6ab8645f0.png

Now we can calculate the size distributions in the test image. pore_size_distribution returns a custom object with information of the distribution of the pore sizes. The x axis in the following images is the Log(pore radius).The histogram of logarithm (base-10) of pore sizes is useful to plot wide size distributions or to better visualize the data in the small size region.

data = ps.metrics.pore_size_distribution(im=im)
fig, ax = plt.subplots(1, 3, figsize=[10, 4])
ax[0].plot(data.bin_centers,data.pdf)
ax[1].plot(data.bin_centers,data.cdf)
ax[2].bar(data.bin_centers, data.cdf, data.bin_widths, edgecolor='k')
ax[0].set_title("Probability Density Function")
ax[1].set_title("Cumulative Density Function")
ax[2].set_title('Bar Plot');
../../../_images/9f2840e5995a82e877ab623170e360be06420889ccea5e8ad29101fa28bbac22.png

bins

The default number of bins for the histogram is 10. Let’s increase the bins to 100:

data = ps.metrics.pore_size_distribution(im=im, bins=100)
fig, ax = plt.subplots(1, 3, figsize=[10, 4])
ax[0].plot(data.bin_centers,data.pdf)
ax[1].plot(data.bin_centers,data.cdf)
ax[2].bar(data.bin_centers, data.cdf, data.bin_widths, edgecolor='k')
ax[0].set_title("Probability Density Function")
ax[1].set_title("Cumulative Density Function")
ax[2].set_title('Bar Plot');
../../../_images/36912e2875533ece74ec2f48511375fe0b2f958a60b822dd1c79a757d09dd2c8.png

Plot results:

log

By default, the histogram binning is based on log(pore radius). We can calculate the size distribution base on pore radius with log=False. The resulting histogram binning is then performed on the pore radius values instead of log(pore radius. Note that for calculating the pore sizes base on diameter, bin_centers returned by pore_size_distribution must be multiplied by 2.

data = ps.metrics.pore_size_distribution(im=im, log=False)
fig, ax = plt.subplots(1, 3, figsize=[10, 4])
ax[0].plot(data.bin_centers,data.pdf)
ax[1].plot(data.bin_centers,data.cdf)
ax[2].bar(data.bin_centers, data.cdf, data.bin_widths, edgecolor='k')
ax[0].set_title("Probability Density Function")
ax[1].set_title("Cumulative Density Function")
ax[2].set_title('Bar Plot');
../../../_images/5eb579e1e4f4dfb98e56ac4665ee66cf69e6750f3bbff70b778e45056b4f6f70.png

voxel_size

By default the voxel_size is 1. We can assign voxel size of the image as the input or apply the scaling on the results after the fact:

voxel_size=1e-3
data = ps.metrics.pore_size_distribution(im=im, voxel_size=voxel_size, log=False)
fig, ax = plt.subplots(1, 2, figsize=[10, 4])
ax[0].bar(data.bin_centers, data.cdf, data.bin_widths, edgecolor='k');
ax[0].set_title("PDF scaling included in the result");
data = ps.metrics.pore_size_distribution(im=im, log=False)
ax[1].bar(data.bin_centers*voxel_size, data.cdf, data.bin_widths*voxel_size, edgecolor='k');
ax[1].set_title("PDF scaling after the result");
../../../_images/078f3a1287c1adbe4e517a8a1cccf56f0381bded163a901a127bd165040b22de.png