How it works
PoreSpy is an open-source Python toolkit for images of porous materials, such as X-ray tomography of rock, battery electrodes, filters, bone or fuel-cell layers [1]. Alongside its analysis tools it has generators: recipes for artificial microstructures with known statistics, used to test methods, train models, or stand in for a sample nobody has scanned yet. This page ports twelve of them to Rust compiled to WebAssembly, so they run in the browser with nothing sent to a server.
The generators
- Blobs: random noise blurred with a Gaussian and cut at the level that gives the porosity; blobiness sets the blur. Rocks, soils and sintered powders.
- Overlapping spheres: spheres dropped at random until the porosity is reached, free to overlap. A classic model for which much is known exactly [2].
- Polydisperse spheres: the same, with radii taken from a normal or uniform distribution.
- Random packing: spheres placed one by one wherever they fit without overlapping, until no room is left (random sequential addition).
- Gravity packing: candidate positions tried from the bottom up, so spheres settle in layers against the floor, as in a packed column.
- Fibres: straight cylinders at random positions, tilted within the limits you set. Paper, felts, gas diffusion layers.
- Voronoi foam: the edges of a random Voronoi tessellation, thickened into struts. Open-cell metal and polymer foams.
- Fractal noise: several octaves of simplex noise, cut at the porosity. Multi-scale textures.
- Sphere lattice: spheres on a simple, body-centred or face-centred cubic lattice.
- TPMS: a sheet around a triply periodic minimal surface such as Schoen's gyroid, the structures used for 3D-printed lattices and heat exchangers.
- Sierpinski foam and Cantor dust: deterministic and random fractals.
The measurements
Pore size is the local thickness: each pore voxel gets the radius of the largest sphere that contains it and fits inside the pore space [3]. It is worked out from the exact Euclidean distance transform [4], one radius at a time, as in PoreSpy's local_thickness(method='dt'). Percolating is the share of the pore space connected to both the bottom and the top face, counting face neighbours. The two-point correlation starts at the porosity and falls to its square for points too far apart to be related; how quickly it falls is a length scale of the structure [2]. Chords are straight runs of pore along the three axes, leaving out those cut by the edge of the image. Specific surface counts voxel faces between pore and solid, times 2/3 to correct the staircase overestimate for surfaces at random angles.
Checked against PoreSpy
Each piece is tested against PoreSpy 3.3. The deterministic ones agree voxel for voxel: the distance transform, the Gaussian blur behind blobs (to 10⁻¹²), sphere lattices of all three kinds, five TPMS surfaces, Sierpinski foams and local thickness on a test image. The random ones can't match voxel for voxel because they draw different random numbers, so their average porosity over twelve samples is compared with PoreSpy's, within the scatter between samples, and the two-point correlation of blobs is compared curve against curve.
Where it differs from PoreSpy
- Voronoi foam: PoreSpy computes the tessellation with SciPy and draws each edge as a line of voxels. Here a voxel belongs to an edge when it lies within 0.7 voxels of the line equidistant from its three nearest seeds, a width chosen to match PoreSpy's edge volume.
- Fibres: PoreSpy aims for the porosity in three batches sized from an estimate of the volume per fibre. It lands about 0.02 short of the target on average, and can overshoot badly, or stop with an error, when the first batch barely touches the image. Here fibres go in one at a time until the porosity is reached.
- Cantor dust uses exact blocks where PoreSpy's upsampling makes them slightly uneven, and fractal noise uses its own simplex noise where PoreSpy calls FastNoiseSIMD.
- The two-point correlation is taken along the three axes. PoreSpy's averages over all directions with Fourier transforms, which gives the same curve for structures without a preferred direction.
- Gravity packing settles along the vertical axis, PoreSpy's
axis=2.
- The 3D view draws a smoothed surface mesh of the solid (surface nets). The measurements and downloads use the voxels themselves.
Taking it further
The download is a NumPy boolean array, True for pore, as PoreSpy expects: im = np.load('pores.npy'). From there PoreSpy can extract a pore network for OpenPNM, simulate mercury intrusion, or compute tortuosity.
References
- J. T. Gostick, Z. A. Khan, T. G. Tranter, M. D. R. Kok, M. Agnaou, M. Sadeghi and R. Jervis, PoreSpy: a Python toolkit for quantitative analysis of porous media images, Journal of Open Source Software 4 (2019) 1296.
- S. Torquato, Random Heterogeneous Materials: Microstructure and Macroscopic Properties, Springer (2002).
- T. Hildebrand and P. Rüegsegger, A new method for the model-independent assessment of thickness in three-dimensional images, Journal of Microscopy 185 (1997) 67–75.
- P. F. Felzenszwalb and D. P. Huttenlocher, Distance transforms of sampled functions, Theory of Computing 8 (2012) 415–428.