regionprops_3D#

This is similar to the regionprops in scikit-image but has some extra features that are relevant to 3D images. Note that the scikit-image version has been adding 3D capabilities, make the PoreSpy version less useful.

import matplotlib.pyplot as plt
import scipy.ndimage as spim

import porespy as ps

ps.visualization.set_mpl_style()
im = ps.generators.random_spheres(shape=[80, 80, 80], r=10, clearance=3)

fig, ax = plt.subplots(figsize=[4, 4])
ax.imshow(im[20, ...], origin="lower", interpolation="none")
ax.axis(False);
../../../_images/e5be0a7bdf204f2db6664837b670023858fb6e251fbc68ea9db9c410d4485b0f.png

We need to label each sphere so they are recognized as individual regions:

regions = spim.label(im)[0]

fig, ax = plt.subplots(figsize=[4, 4])
ax.imshow(regions[20, ...], origin="lower", interpolation="none")
ax.axis(False);
../../../_images/7dad5492b3371c50106e3f5e4e483b67a9d5165f3c79b2a5dec4aa506be4acf1.png
props = ps.metrics.regionprops_3D(regions)

props is a list of RegionProperties objects, subclassed from scikit-image. Each RegionProperties object possess the properties as attributes. Note that these are calculated on demand, so the regionsprops_3D function appears very quick, but the work has not yet been done.

props
[<RegionPropertiesPS: label=1, bbox=(4, 57, 56, 25, 78, 77)>,
 <RegionPropertiesPS: label=2, bbox=(8, 32, 42, 29, 53, 63)>,
 <RegionPropertiesPS: label=3, bbox=(11, 1, 41, 32, 22, 62)>,
 <RegionPropertiesPS: label=4, bbox=(12, 54, 6, 33, 75, 27)>,
 <RegionPropertiesPS: label=5, bbox=(14, 18, 12, 35, 39, 33)>,
 <RegionPropertiesPS: label=6, bbox=(21, 54, 30, 42, 75, 51)>,
 <RegionPropertiesPS: label=7, bbox=(27, 45, 55, 48, 66, 76)>,
 <RegionPropertiesPS: label=8, bbox=(30, 19, 40, 51, 40, 61)>,
 <RegionPropertiesPS: label=9, bbox=(34, 30, 1, 55, 51, 22)>,
 <RegionPropertiesPS: label=10, bbox=(37, 1, 58, 58, 22, 79)>,
 <RegionPropertiesPS: label=11, bbox=(41, 4, 15, 62, 25, 36)>,
 <RegionPropertiesPS: label=12, bbox=(46, 49, 30, 67, 70, 51)>,
 <RegionPropertiesPS: label=13, bbox=(51, 48, 5, 72, 69, 26)>,
 <RegionPropertiesPS: label=14, bbox=(54, 55, 53, 75, 76, 74)>,
 <RegionPropertiesPS: label=15, bbox=(56, 20, 44, 77, 41, 65)>,
 <RegionPropertiesPS: label=16, bbox=(58, 22, 5, 79, 43, 26)>]

The properties of regions 1 are on the RegionsProperties object located at position 0 in the props list:

for d in dir(props[0]):
    if not d.startswith("_"):
        print(d)
area
area_bbox
area_convex
area_filled
axis_major_length
axis_minor_length
bbox
bbox_volume
border
centroid
centroid_local
centroid_weighted
centroid_weighted_local
convex_volume
coords
coords_scaled
dt
eccentricity
equivalent_diameter_area
euler_number
extent
feret_diameter_max
image
image_convex
image_filled
image_intensity
inertia_tensor
inertia_tensor_eigvals
inscribed_sphere
intensity_max
intensity_mean
intensity_median
intensity_min
intensity_std
label
mask
moments
moments_central
moments_hu
moments_normalized
moments_weighted
moments_weighted_central
moments_weighted_hu
moments_weighted_normalized
num_pixels
orientation
perimeter
perimeter_crofton
skeleton
slice
slices
solidity
sphericity
surface_area
surface_mesh_simplices
surface_mesh_vertices
volume

Let’s check a few of the properties:

print(props[0].volume)
5497.0

Because the present function is meant for 3D images, we have added specific terminology, like volume, instead of allowing area to mean volume like the scikit-image version”

print(props[0].area)
5497.0

We do have a surface_area, which is also specific to 3D objects:

print(props[0].surface_area)
1407.9961

In addition to scalar metrics, we also provide access to useful images of the region:

fig, ax = plt.subplots(figsize=[4, 4])
ax.imshow(props[0].dt[5, ...])
ax.axis(False);
../../../_images/65eb80fbcf523f695cbffc8ac29e169aab0d88032ad0a8dc6965ce8991000ef0.png