256 Shades of Grey, tortuosity from a scan with no segmentation

Random walkers diffuse through an image or 3D scan of a porous material, and how fast they spread gives its tortuosity. The grey levels are used as they are.

Published
15 November 2026
Run
In the browser; your scan stays on your machine
Input
TIFF stacks (8 or 16-bit), PNG, JPG
Stack
Rust, webassembly, webgl
Download
250 KB
Open gtrax
Contents
  1. Two ways to get a number from a scan
  2. Grey is how open a voxel is
  3. What a grey level can and cannot say
  4. Reading the tortuosity off the spread
  5. Watching a burst
  6. Checked against cases with known answers
  7. Small enough to just open
  8. Try it
  9. Further reading
gtrax: a slice of a porous volume with green walkers filling its open space, a 3D view of the volume, and the tortuosity along each axis
fig. 1 — the demo volume, with walkers spread through its open space. They travel far more slowly through the stack (z) than across it.

Tortuosity is how much a material’s geometry slows diffusion down. In a battery electrode it sets how quickly ions can reach the active particles; in a catalyst, a filter or a rock it plays the same part for whatever has to move through the pores.

Strictly, the number wanted is the tortuosity factor, τ: how much lower the effective diffusivity through the material is than its porosity alone would explain, Deff = D ε / τ. It is not the everyday tortuosity, the length of a winding path over the straight-line distance. For a bundle of simple capillaries the factor is the square of that ratio, because a longer pore of the same volume is also a narrower one; Epstein set out the difference in 1989, and the two are still often mixed up.

The old shortcut is a correlation such as Bruggeman’s, τ = ε−1/2, which needs nothing but the porosity. It was derived for isotropic, randomly placed particles, and it says nothing about direction: a material whose particles lie flat can be far more tortuous through its thickness than across it at the same porosity. So the factor is now usually measured from a scan, an X-ray tomogram or a stack of microscope images.

That route has a step in the middle that causes most of the arguments. The scan is greyscale, and before anything can be simulated it is segmented: every voxel is called pore or solid by a threshold. But at the resolution of a real scan many voxels are partly both, and where the threshold goes can move the answer by more than the effect being studied.

Battery electrodes show what is at stake. The carbon and binder that hold the particles together form a web of pores too fine for X-ray CT to resolve, so it reads as open space. A study of fourteen electrodes that put the binder back found tortuosity factors 1.35 to 1.81 times higher than those worked out from the particles alone.

The app described here, gtrax, skips that step. Open it, drop in a scan, and it works on the grey levels as they are.

Two ways to get a number from a scan

Once a scan is segmented there are two ways to get the tortuosity factor from it. One holds a concentration difference across the volume and solves for the steady flow through the pores, voxel by voxel; TauFactor does this, quickly, on volumes of hundreds of millions of voxels. The other lets random walkers loose in the pores and watches how fast they spread. The physics is the same, since diffusion is what a crowd of independent random walkers does on average.

pytrax is a compact version of the second, for black-and-white images. Walkers step between neighbouring pore voxels and bounce off solid ones; at the edge of the image they carry on into a mirrored copy of it, so the walk is not boxed in; and the tortuosity along each axis comes from the slope of their mean squared displacement. The name gtrax is pytrax (tortuosity from random axial movement) with a g for grey. It starts from pytrax and changes one thing: the image no longer has to be black and white.

Grey is how open a voxel is

Each grey level is read as an openness between 0 and 1. Below a pore threshold a voxel is fully open; above a solid threshold it is closed; between the two it is partly open, on a ramp that can be bent with an exponent. The default exponent, 1.5, is the one in Bruggeman’s correlation, applied to each part-open voxel as if it were a small porous medium of its own. Every scan is first scaled to 8 bits, so there are exactly 256 shades of grey to work with. The thresholds start where the histogram splits naturally into a dark group and a bright one, and can be moved while the walkers run.

Thousands of walkers are then let loose, each starting at a random place in the open space, so the measurement averages over the whole volume from the first step. At each step a walker picks a neighbour at random and moves there with a probability set by how open both voxels are; otherwise it waits. A walk that sometimes waits instead of stepping is still diffusion, only slower, so a grey voxel holds walkers up without trapping them. The probability is the harmonic mean of the two, 2pipj / (pi + pj), the same rule as two resistances in series, so a thin, nearly closed wall slows a walker as much as it should.

gtrax on the demo image: flattened grey particles with green walkers in the gaps between them; tortuosity 1.5 across and 3.0 down
fig. 2 — the demo image: flattened particles with soft grey edges. Getting from top to bottom is about twice as tortuous as getting across.

What a grey level can and cannot say

Reading grey as “how much of the voxel is pore” rests on an assumption. A CT grey value is the X-ray attenuation averaged over the voxel, and each material attenuates differently: copper, for example, far more strongly than aluminium. With pore and a single solid, a voxel’s grey level is a straight line between the two, and the ramp reads it correctly, as long as the thresholds sit on the two peaks of the histogram. With more than one solid, a grey level has more than one explanation: a voxel half full of a strongly attenuating material can look exactly like one full of a weakly attenuating one. A single scan cannot tell them apart, and gtrax does not try.

A good fit is a graphite anode. The particles are one solid, and what sits between them and the pore in grey is what should be partly open: the edges of particles, and the carbon and binder whose pores are too fine to resolve. A poor fit is a silicon–graphite composite anode. Silicon attenuates much more strongly than graphite, so with the thresholds running from pore to silicon, the graphite particles land partway up the ramp and the walkers pass through solid graphite. A scan that still includes the copper current collector goes wrong in the same way. In cases like these it is better to segment the solids first, or at least to check the histogram and crop away what does not belong to the material being measured.

Reading the tortuosity off the spread

In open space the mean squared distance a walker has travelled along each axis grows in a straight line with the number of steps. In the material it still grows in a straight line once the walkers have wandered far enough, but more slowly. The ratio of the two slopes is how much the material slows diffusion along that axis.

The tortuosity factor takes the porosity out of that, and on a grey map there is a subtlety. Walkers spread evenly over every voxel that is open at all, so a half-open voxel holds as many of them as a fully open one, yet it is only half pore. The app corrects for this: it divides the porosity (counting a part-open voxel as part pore) by the slope and by the fraction of voxels that are open at all. Without the correction, a scan in which every voxel is half open would read 2.83; with it, it reads 1.41, which is what Bruggeman’s correlation gives for such a material. On a black-and-white map the two porosities are the same and the correction does nothing.

The app fits the slope over the second half of the line and updates it as the walkers go, so the numbers settle in front of you.

The start is left out for a reason. At first a walker only meets the walls of the pore it began in, and the spread is not yet a straight line: the apparent diffusivity changes with time and settles only once walkers have crossed many pores. Measurements of restricted diffusion by NMR work on the same principle, and the time dependence itself says something about the pore space. In practice it means the walk has to be long compared with the pores; the chart shows the line, so it is plain when it has straightened out. Moving a threshold does not scatter the walkers again: they stay where they are and a new line starts from there, so the reading is for the new map alone and settles in seconds.

Ticking “one threshold” turns the map black and white, which is the classic walk on a segmented image, so the two can be compared on the same scan. On the demo volume they come out within a few per cent of each other. The walk can also be run through either phase. The dark phase is usually the pore space; the bright phase is usually the solid, whose tortuosity matters for anything that travels through the particles, such as electrons in an electrode.

Because each axis is measured separately, anisotropy shows up directly. The demo volume is packed with particles flattened in one direction, and its tortuosity through the stack comes out close to twice what it is across it, while the two directions across agree. Calendered battery electrodes are like this: pressing lines graphite flakes up in the plane of the electrode and makes the way through its thickness the slow one. The slice can be cut across any of the three axes, so the layering is plain to see side on.

Watching a burst

The picture the app opens on is not the measurement. A burst of walkers is released at one point, the centre to begin with or wherever the slice is clicked, and the shading shows how many have reached each spot, with lines where that falls to a half and to an eighth of the peak. On the demo volume, cut side on, the cloud comes out wider than it is deep: the anisotropy above, made visible.

A burst’s own spread would make a poor measurement. Every walker in it explores the same patch of material, so adding walkers does not help; the spread only settles on the volume’s value once the cloud has crossed many grains, and in most scans it reaches the edges first. Walkers started evenly through the whole volume average over every part of it from the first step, which is why the numbers come from those. A burst still says something. Where a cloud stalls is a local bottleneck, and the way it stretches is the fast direction. The Picture switch shows the measuring walkers instead.

Checked against cases with known answers

A random walk is easy to get subtly wrong, so the engine is tested against cases with an answer on paper. A uniform material where every voxel is half open must slow diffusion by exactly half, and with Bruggeman’s exponent must give his tortuosity factor of 1.41. A stack of alternating open and half-closed layers must match the series rule across the layers and the parallel rule along them. Straight channels segmented at one threshold must give a tortuosity of exactly 1 along them and an enormous one across, whichever phase is walked. All of these come out within the statistical noise of the walk, which is a per cent or two. The edges of the scan act as mirrors, so any data works without padding.

Small enough to just open

The engine is about 900 lines of Rust compiled to WebAssembly, and the whole app is a quarter of a megabyte. There is no server: a TIFF stack of up to 64 million voxels is decoded in the browser and never uploaded anywhere, which matters when the scan belongs to someone else. Each walker has its own random number stream, so they stay independent, and the 3D view is plain WebGL drawing each burst as a cloud inside the volume as it spreads.

Try it

Open gtrax in a browser. It starts on a demo volume; upload a TIFF stack for 3D or a PNG or JPG for 2D, or drop one anywhere on the page.

Further reading