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

Porosity says how much room there is to diffuse, and nothing about which way is easy. gtrax, a browser version of pytrax that also reads greys, sends random walkers through a scan and measures the tortuosity along every axis.

Published
15 November 2026
Reads
TIFF stacks (8 or 16-bit), PNG or JPG; none of it uploaded
Examples
A 128³ volume and a 512² image of flattened grains
Method
Pytrax's random walk, with greys as part-open voxels
Download
360 KB, of which the engine is 250 KB
Open gtrax Source code on GitHub Based on pytrax on GitHub
Contents
  1. A factor, rather than a path length
  2. Where the threshold argument starts
  3. pytrax, with the greys left in
  4. 256 shades of open
  5. When one grey has two explanations
  6. Waiting for the line to straighten
  7. A burst shows the way, not the number
  8. Materials with answers on paper
  9. Held up against pytrax
  10. Data
  11. Further reading
A slice of a porous volume with green walkers filling its open space between grey particles, beside a 3D view of the volume with the slice inside it
fig. 1 — the demo volume, with walkers spread through its open space: one slice on the left, the whole volume on the right.

Take a block that is half open space and pack the other half with grains squashed in one direction. Along the plane the grains lie in, its tortuosity factor settles near 1.4. Through the stack it settles near 2.4, about 1.7 times as high. Bruggeman’s correlation, the usual shortcut from porosity alone, gives 1.4 for every direction.

Those figures come from the demo volume in gtrax, after 30,000 steps or more of a random walk. The gap matters in real materials. Calendering a battery electrode lines its graphite flakes up in the plane, which makes the way through its thickness, the way the ions have to go, the slow one. In a catalyst, a filter or a rock the geometry holds back whatever else has to move through the pores.

A factor, rather than a path length

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

Bruggeman’s τ = ε−1/2 needs only the porosity because it was derived for isotropic, randomly placed particles. Once particles lie flat it has no way of knowing, which is why the factor is now usually measured from an X-ray tomogram or a stack of microscope images.

Where the threshold argument starts

A scan is greyscale, and before anything can be simulated it is normally segmented: every voxel is called pore or solid by a threshold. At the resolution of a real scan many voxels are partly both, and the choice of threshold 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, which then 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.

pytrax, with the greys left in

Once a scan is segmented there are two routes to τ. TauFactor takes the first: hold a concentration difference across the volume and solve for the steady flow through the pores, voxel by voxel, which it does quickly on hundreds of millions of voxels. The second lets random walkers loose in the pores and watches how fast they spread. The two are equivalent, since diffusion is what a crowd of independent random walkers does on average.

pytrax does the second, on black-and-white images. Its walkers step between neighbouring pore voxels, bounce off solid ones and, at the edge of the image, carry on into a mirrored copy, so any data works without padding. The slope of their mean squared displacement gives the tortuosity along each axis. gtrax is a browser version of pytrax (tortuosity from random axial movement), with a g for grey: the image no longer has to be black and white.

256 shades of open

Every scan is scaled to 8 bits, which leaves 256 shades of grey, and every shade is read as an openness between 0 and 1. Below a pore threshold a voxel is fully open and above a solid threshold it is closed. Between them runs a ramp that can be bent with an exponent. The default, 1.5, is the one in Bruggeman’s correlation, applied to a part-open voxel as if it were a small porous medium of its own. The thresholds start where the histogram splits into a dark group and a bright one, and can be moved while the walkers run.

Thousands of walkers start at random places in the open space, so the measurement averages over the whole volume from the first step. At every 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 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), as for two resistances in series, and a thin, nearly closed wall slows a walker as much as it should.

gtrax on the demo image: flattened grey particles, with a green burst of walkers spreading further across the gaps than 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.

When one grey has two explanations

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 materials attenuate differently, copper far more strongly than aluminium. With pore and a single solid the 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. Add a second solid and 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 graphite anode suits it well. The particles are one solid, and the greys between them and the pore are what should be partly open: particle edges, and carbon and binder with pores too fine to resolve. A silicon–graphite anode suits it badly. Silicon attenuates much more strongly, so with the ramp running from pore to silicon the graphite lands partway up and the walkers pass through solid particles. A copper current collector left in the scan does similar damage. Segment the solids first in such cases, or at least check the histogram and crop away what is not being measured.

Waiting for the line to straighten

In open space the mean squared distance along each axis grows in a straight line with the number of steps. In the material it does so too once the walkers have wandered far enough, but more slowly, and the ratio of the two slopes is how much diffusion is slowed along that axis. gtrax draws those lines in the corner of the slice, with the τ they give as the key.

Early readings are too low. At first a walker meets only the walls of the pore it began in, and the apparent diffusivity keeps falling until it has crossed many pores, an effect that NMR measurements of restricted diffusion use to learn about pore space. On the demo volume τ through the stack reads about 1.9 after 700 steps and about 2.4 after 30,000. The fit leaves out the first half of the line for this reason, but the walk still has to be long compared with the pores, so turn Speed up and watch for the numbers to stop climbing.

Porosity then has to be taken out of the slope, 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 as a fully open one although it is only half pore. The app divides the porosity, counting a part-open voxel as part pore, by the slope and by the fraction of voxels open at all. Without this, a scan with every voxel half open would read 2.83; with it, 1.41, which is Bruggeman’s value for such a material. On a black-and-white map the two porosities are equal and the correction does nothing.

Moving a threshold leaves the walkers where they are and starts a new line, so the reading is for the new map alone. “One threshold” makes the map black and white, the classic walk on a segmented image, for comparison: on the demo volume the two agree to within a few per cent. Either phase can be walked. The dark one is usually pore; the bright one is usually solid, whose tortuosity matters to anything travelling through the particles, such as electrons in an electrode.

A burst shows the way, not the number

The picture gtrax opens on is not the measurement. A burst of walkers is released at one point, the centre or wherever you click, and shaded by how many have reached each spot, with lines at a half and an eighth of the peak. Cut the demo volume side on and the cloud comes out wider than it is deep. Where a cloud stalls is a local bottleneck, and the way it stretches is the fast direction.

Its own spread would make a poor measurement. All the walkers in a burst explore one patch of material, so adding more does not help, and in most scans the cloud reaches the edges before it has crossed enough grains to speak for the volume. The numbers always come from the walkers started evenly through the whole volume, which the Picture switch will show you.

Materials with answers on paper

A random walk is easy to get subtly wrong, so the engine’s tests use materials that can be solved by hand. A uniform block of half-open voxels must slow diffusion by exactly half, and with Bruggeman’s exponent must give 1.41. Alternating open and part-closed layers must obey the series rule across and the parallel rule along. Straight channels cut at one threshold must give exactly 1 along them and an enormous value across, whichever phase is walked. With 40,000 walkers the statistical noise is about 1.2%, and the tests allow three times that, 4%.

Held up against pytrax

Cut at one threshold, every voxel is pore or solid and gtrax’s walk is pytrax’s walk: the same steps, the same bounce off solid, the same mirrored copies at the edges. On the same image the two should give the same tortuosity, up to random noise. The check makes two black-and-white images with PoreSpy, a 256² image of blobs at 60% porosity and a 96³ volume of blobs flattened along z at 50%, and runs pytrax 0.1.2 and gtrax’s engine on each, five times with 10,000 walkers for 20,000 steps.

ImageAxispytraxgtraxDifference
2D blobsx3.00 ± 0.022.99 ± 0.01−0.2%
2D blobsy3.29 ± 0.023.30 ± 0.02+0.3%
3D blobsx1.69 ± 0.011.71 ± 0.01+1.0%
3D blobsy1.72 ± 0.011.71 ± 0.01−0.7%
3D blobsz5.11 ± 0.025.10 ± 0.02−0.2%

Both columns use pytrax’s fit, a line through the origin over the whole walk, and the ± is the standard error over the five runs. Every axis agrees to within 1%, and every difference is within about one and a half standard errors, which is what noise alone would give. Fitting both the way gtrax does, over the second half with an intercept, the differences stay within 2.2%, again inside the noise.

The two fits do not agree with each other on the 2D image: 3.0 through the origin, against 3.9 over the second half. That is the effect described above. The early steps, when walkers have yet to leave their first pore, pull a fit over the whole walk down, and this image’s pores are big enough that 20,000 steps is not long compared with them. On the 3D volume the fits agree within 2%.

Data

Both examples are synthetic and generated in the page, so there is no scan to credit. Your own TIFF stack (up to 64 million voxels), PNG or JPG is decoded in the browser and never uploaded, which matters when the scan belongs to someone else.

Further reading