representative_elementary_volume(im, npoints=1000)[source]

Calculates the porosity of the image as a function subdomain size. This function extracts a specified number of subdomains of random size, then finds their porosity.

  • im (ND-array) – The image of the porous material

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


result – A tuple containing the volume and porosity of each subdomain tested in arrays npoints long. They can be accessed as attributes of the tuple. They can be conveniently plotted by passing the tuple 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



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.

Also, this function is a prime target for parallelization since the npoints are calculated independenlty.


[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.