representative_elementary_volume(im, npoints=1000)[source]

Calculates the porosity of an image as a function subdomain size.

This function extracts a specified number of subdomains of random size, then finds their porosity.

  • im (ndarray) – The image of the porous material

  • npoints (int) – The number of randomly located and sized boxes to sample. The default is 1000.


result – A custom object with the following data added as named attributes:


The total volume of each cubic subdomain tested


The porosity of each subdomain tested

These attributes can be conveniently plotted by passing the Results object to matplotlib’s plot function using the * notation: plt.plot(*result, 'b.'). The resulting plot is similar to the sketch given by Bachmat and Bear [1]

Return type

Results object


This function is frustratingly slow. Profiling indicates that all the time is spent on scipy’s sum function which is needed to sum the number of void voxels (1’s) in each subdomain.


[1] Bachmat and Bear. On the Concept and Size of a Representative Elementary Volume (Rev), Advances in Transport Phenomena in Porous Media (1987)


Click here to view online example.