Feature extraction
The qim3d
library provides a set of methods for feature extraction on volumetric data
qim3d.features
qim3d.features.area
Compute the surface area of a 3D volume or mesh.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
ndarray or Trimesh
|
Either a np.ndarray volume or a mesh object of type trimesh.Trimesh. |
required |
**mesh_kwargs |
Any
|
Additional arguments for mesh creation if the input is a volume. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
area |
float
|
The surface area of the object. |
Example
Compute area from a mesh:
import qim3d
# Load a mesh from a file
mesh = qim3d.io.load_mesh('path/to/mesh.obj')
# Compute the surface area of the mesh
area = qim3d.features.area(mesh)
area = qim3d.features.area(mesh)
print(f"Area: {area}")
Compute area from a np.ndarray:
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
# Compute the surface area of the blob
volume = qim3d.features.area(synthetic_blob, level=0.5)
volume = qim3d.features.area(synthetic_blob, level=0.5)
print('Area:', volume)
Source code in qim3d/features/_common_features_methods.py
qim3d.features.volume
Compute the volume of a 3D volume or mesh.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
ndarray or Trimesh
|
Either a np.ndarray volume or a mesh object of type trimesh.Trimesh. |
required |
**mesh_kwargs |
Any
|
Additional arguments for mesh creation if the input is a volume. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
volume |
float
|
The volume of the object. |
Example
Compute volume from a mesh:
import qim3d
# Load a mesh from a file
mesh = qim3d.io.load_mesh('path/to/mesh.obj')
# Compute the volume of the mesh
vol = qim3d.features.volume(mesh)
print('Volume:', vol)
Compute volume from a np.ndarray:
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
# Compute the volume of the blob
volume = qim3d.features.volume(synthetic_blob, level=0.5)
volume = qim3d.features.volume(synthetic_blob, level=0.5)
print('Volume:', volume)
Source code in qim3d/features/_common_features_methods.py
qim3d.features.sphericity
Compute the sphericity of a 3D volume or mesh.
Sphericity is a measure of how spherical an object is. It is defined as the ratio of the surface area of a sphere with the same volume as the object to the object's actual surface area.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
ndarray or Trimesh
|
Either a np.ndarray volume or a mesh object of type trimesh.Trimesh. |
required |
**mesh_kwargs |
Any
|
Additional arguments for mesh creation if the input is a volume. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
sphericity |
float
|
A float value representing the sphericity of the object. |
Example
Compute sphericity from a mesh:
import qim3d
# Load a mesh from a file
mesh = qim3d.io.load_mesh('path/to/mesh.obj')
# Compute the sphericity of the mesh
sphericity = qim3d.features.sphericity(mesh)
sphericity = qim3d.features.sphericity(mesh)
Compute sphericity from a np.ndarray:
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
# Compute the sphericity of the blob
sphericity = qim3d.features.sphericity(synthetic_blob, level=0.5)
sphericity = qim3d.features.sphericity(synthetic_blob, level=0.5)
Limitations due to pixelation
Sphericity is particularly sensitive to the resolution of the mesh, as it directly impacts the accuracy of surface area and volume calculations. Since the mesh is generated from voxel-based 3D volume data, the discrete nature of the voxels leads to pixelation effects that reduce the precision of sphericity measurements. Higher resolution meshes may mitigate these errors but often at the cost of increased computational demands.