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 porespy as ps
import numpy as np
import matplotlib.pyplot as plt
import scipy.ndimage as spim
[03:28:09] ERROR    PARDISO solver not installed, run `pip install pypardiso`. Otherwise,          _workspace.py:56
                    simulations will be slow. Apple M chips not supported.                                         
im = ps.generators.rsa([80, 80, 80], r=10, clearance=3)
plt.imshow(im[20, ...], origin='lower', interpolation='none');
/tmp/ipykernel_4978/538947285.py:1: DeprecationWarning: Call to deprecated function (or staticmethod) rsa. (This function will be renamed random_spheres in a future version)
  im = ps.generators.rsa([80, 80, 80], r=10, clearance=3)
../../../_images/a1cb000329be01873a59962d6e1a3222823d01ba18b8dd160ff799d7481135b4.png

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

regions = spim.label(im)[0]
plt.imshow(regions[20, ...], origin='lower', interpolation='none');
../../../_images/67bff95d80658a84b7ec573624a3fde85fb82aad45c63f88387e9eaf12a32ae1.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
[<porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1250>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9fc70>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9fca0>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9f4f0>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9f910>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9fc40>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9ff70>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9f9d0>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9f3d0>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9f2b0>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9faf0>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f256cb9f160>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1c70>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1d30>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1b20>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb16d0>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb11f0>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1520>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1430>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1d60>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1d90>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1e20>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1e50>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1670>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1400>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb13d0>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1e80>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb1220>,
 <porespy.metrics._regionprops.RegionPropertiesPS at 0x7f250bbb12e0>]

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_min
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)
4139.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)
4139.0

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

print(props[0].surface_area)
1165.306396484375

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

plt.imshow(props[0].dt[5, ...]);
../../../_images/b8a7575f051bcbdeaac93427bda4ca411e8367aabc345ed604149433c51dfea8.png