mesh_volume#
Calculates the volume of a single region by meshing it. This method works by applying Trimesh on the region to mesh the region using marching cube algorithm and calculate the volume of the meshed region.
import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
regions#
The input image with a single region labelled as True or any value>0. The image can be 3D or 2D. For visualization purpose, we create a 2D test image:
np.random.seed(10)
im = ps.generators.blobs(shape=[50, 50])
snow = ps.filters.snow_partitioning(im)
regions = snow.regions
region = regions == 10
volume = ps.metrics.mesh_volume(region)
print("volume is=", volume)
fig, ax = plt.subplots(1, 1, figsize=[6, 6])
ax.imshow(region, origin="lower", interpolation="none")
ax.axis(False);
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
File ~/work/porespy/porespy/src/porespy/metrics/_meshtools.py:105, in mesh_volume(region, voxel_size)
104 try:
--> 105 from trimesh import Trimesh
106 except ModuleNotFoundError:
ModuleNotFoundError: No module named 'trimesh'
During handling of the above exception, another exception occurred:
ModuleNotFoundError Traceback (most recent call last)
Cell In[2], line 6
4 regions = snow.regions
5 region = regions == 10
----> 6 volume = ps.metrics.mesh_volume(region)
7 print("volume is=", volume)
8 fig, ax = plt.subplots(1, 1, figsize=[6, 6])
File ~/work/porespy/porespy/src/porespy/metrics/_meshtools.py:108, in mesh_volume(region, voxel_size)
106 except ModuleNotFoundError:
107 msg = 'The trimesh package can be installed with pip install trimesh'
--> 108 raise ModuleNotFoundError(msg)
110 mc = mesh_region(region > 0, voxel_size=voxel_size)
111 m = Trimesh(vertices=mc.verts, faces=mc.faces, vertex_normals=mc.norm)
ModuleNotFoundError: The trimesh package can be installed with pip install trimesh