PoreSpy's generators, live in the browser

Grow a 3D porous material from one of twelve recipes, cut into it, measure its pores, and copy the same call into Python. PoreSpy's image generators, ported to Rust and run in a browser tab.

Published
19 November 2026
Run
In the browser
Generators
Twelve, from PoreSpy 3.3
Export
.npy, .tif and the PoreSpy call
Stack
Rust, webassembly, webgl
Download
155 KB
Open pores
Contents
  1. Twelve recipes
  2. Measuring what was made
  3. Back to Python
  4. Checked against PoreSpy
  5. Drawn as a surface
  6. What it leaves out
  7. Small enough to just open
  8. Try it
  9. Further reading

Much of what matters about a porous material depends on the shape of its pores. That includes how fast ions reach the particles in a battery electrode, how much water a soil holds, and how easily gas gets through a fuel cell’s diffusion layer. The shape can be scanned, with X-ray tomography or a stack of microscope images, and the scan is an image: a 3D grid of voxels, each one pore or solid.

PoreSpy is an open-source Python toolkit for analysing images like that. Alongside its analysis tools it has generators: recipes for artificial microstructures with known statistics. They are used to test a method on a structure whose answer is known, to train a model on more samples than anyone could scan, or to stand in for a material that hasn’t been made yet. The app described here, pores, runs twelve of those generators in the browser. Open it, pick a recipe and turn the result in 3D.

Twelve recipes

Each generator makes a 3D image from a handful of settings:

  • Noise. Blobs blurs random noise and cuts it at the level that gives the porosity asked for, which looks like a sandstone or a sintered powder. Fractal noise adds noise at several scales, for rougher, multi-scale pores.
  • Overlapping spheres. Spheres dropped at random until the porosity is reached, free to overlap, in one size or a spread of sizes. This is one of the oldest models of a random material, and much about it is known exactly.
  • Packings. Random packing places spheres one at a time wherever they fit, never overlapping, until there is no room for another; this is random sequential addition. Gravity packing tries positions from the bottom up, so the spheres settle in layers against the floor as they do in a packed column.
  • Fibres and foams. Fibres are straight cylinders at random, lying in layers like paper or felt unless they are allowed to tilt. Voronoi foam takes the edges of a random tessellation and thickens them into struts, like an open-cell metal foam.
  • Periodic and fractal. Sphere lattices, simple, body-centred or face-centred cubic. Sheets around triply periodic minimal surfaces such as Schoen’s gyroid, the shape used for 3D-printed lattices and heat exchangers. Sierpinski foam and Cantor dust, which have holes at every scale.

Images can be any shape up to eight million voxels, from a cube to a thin slab or a tall column.

Measuring what was made

Under the 3D view the app measures each image as soon as it is made.

Pore size is the local thickness: every pore voxel gets the radius of the largest sphere that contains it and still fits inside the pore space. It is built from the exact Euclidean distance transform, one radius at a time, as PoreSpy does it. A slice through the image can be coloured by it, and the chart gives the share of the pore volume at each radius.

The two-point correlation is the chance that two points a given distance apart are both in the pore. It starts at the porosity and falls to its square once the points are too far apart to be related; how quickly it falls is a length scale of the structure. Chords are straight runs of pore along the three axes. Percolating is the share of the pore space connected to both the bottom and the top face, the part a fluid could actually flow through. A porosity profile up the image shows layering, such as the ordered first layers of a gravity packing against its floor.

Back to Python

Next to the settings, the app writes out the PoreSpy call that makes the same structure, with the same shape and parameters, and the lines to measure it. The image itself downloads as a NumPy array, True for pore as PoreSpy expects, or as an 8-bit TIFF stack that opens in Fiji or with tifffile. The same seed won’t give the same voxels in Python, because PoreSpy draws from NumPy’s random stream, but the statistics are the same.

Checked against PoreSpy

Every generator is tested against PoreSpy 3.3. The deterministic pieces agree voxel for voxel:

  • the distance transform;
  • the Gaussian blur behind blobs, to one part in 10¹²;
  • all three sphere lattices;
  • five minimal surfaces;
  • the Sierpinski foam;
  • local thickness on a test image.

Each is checked for non-cubic shapes too.

The random generators can’t match voxel for voxel, because they draw different random numbers. Instead, each one’s mean porosity over twelve samples is compared with PoreSpy’s, within the scatter between samples, and the two-point correlation curve of blobs is compared point by point, within 3 per cent.

Testing the fibres turned up something in PoreSpy itself. Asked for a porosity, it adds fibres in three batches, sizing each from an estimate of the volume per fibre so far. It lands about 0.02 short of the target on average. When the first small batch barely touches the image, the estimate collapses and the next batch overshoots badly, and over forty seeds one run stopped with a division by zero. Here the fibres go in one at a time until the porosity is reached.

Two other generators work differently from PoreSpy’s:

  • Voronoi foam: PoreSpy builds the tessellation with SciPy and draws each edge as a line of voxels. Here a voxel is on an edge when it lies within 0.7 voxels of the line equidistant from its three nearest seeds. That width was chosen to match PoreSpy’s edge volume, and the porosity of the two agrees to 0.004.
  • Fractal noise: it uses its own simplex noise where PoreSpy calls a C library.

Drawn as a surface

The 3D view draws the surface of the solid as a mesh of triangles. The worker builds it by surface nets: the image is lightly smoothed, each cube between eight voxel centres that straddles the boundary gets one vertex, and neighbouring vertices are joined into quads. A 128-voxel cube gives about 800,000 triangles in a fraction of a second, and from then on turning the view costs the graphics card almost nothing. Shadowing from nearby solid is worked out once per vertex, so the pores read as depth.

To cut a corner away, or cut the volume at the slice being viewed, the cut region is emptied and the mesh made again, so every cut comes out as a closed face. The smoothing is for the picture only; the measurements and downloads use the voxels as they are.

What it leaves out

PoreSpy goes much further than its generators. It can extract a pore network for OpenPNM, simulate mercury intrusion and drainage, and measure tortuosity; none of that is here yet. Tortuosity has its own app, gtrax, which takes a scan, or one of these images, and finds it from random walkers.

Small enough to just open

The engine is about 1,000 lines of Rust compiled to WebAssembly, and the whole app is about 155 KB. There is no server: images are made and measured in a worker thread on your machine, in about a second for a 128-voxel cube.

Try it

Open pores in a browser. It starts on blobs. Try gravity packing in a tall column, fibres with and without tilt, or the gyroid, and use the theme button for a CT-scan look.

Further reading