Particle shape analysis and visualization library.
Project description
PartiMorph
PartiMorph analyzes a single 2D binary particle mask and returns geometric shape metrics.
| Metric | Meaning |
|---|---|
| Wadell roundness | Corner curvature-based roundness |
| Circularity | 4 * pi * area / perimeter^2 |
| Sphericity | Inscribed circle radius divided by enclosing circle radius |
| Aspect ratio | Fitted ellipse major axis divided by minor axis |
Roundness, circularity, and sphericity are clipped to 0..1. Aspect ratio is >= 1.
Installation
PartiMorph requires Python 3.12+.
pip install partimorph
For local development:
pip install -e ".[dev]"
Quick Start
import partimorph as pm
mask = pm.utils.create_circle_mask((256, 256), (128, 128), 60)
results = pm.analyze_mask(mask)
if results is None:
raise ValueError("mask has no foreground pixels")
print(results["roundness"]["val"])
print(results["circularity"]["val"])
print(results["sphericity"]["val"])
print(results["aspect_ratio"]["val"])
Visualize the results:
pm.utils.plot_analysis_results(mask, results)
API
pm.analyze_mask(
mask,
use_aspect_ratio=True,
use_roundness=True,
use_circularity=True,
use_sphericity=True,
roundness_params=None,
eps=0.001,
target_dim=384,
)
| Parameter | Description |
|---|---|
mask |
2D numpy.ndarray with bool or {0, 1} values |
use_* |
Toggle individual metrics on/off |
roundness_params |
Optional dict to override Wadell roundness parameters |
eps |
Tolerance for geometric computations |
target_dim |
Large masks are downscaled to this size for speed, then coordinates are rescaled |
Returns None for an empty mask. Otherwise, returns an AnalysisResult dict. Disabled metrics are omitted; enabled metrics are present and may be None when the geometry cannot be measured.
Result Shape
{
"roundness": {"val": float} | None,
"circularity": {"val": float} | None,
"sphericity": {
"val": float,
"inscribed": {"x": float, "y": float, "r": float},
"enclosing": {"x": float, "y": float, "r": float},
} | None,
"aspect_ratio": {
"val": float,
"ellipse": {
"major": float, "minor": float,
"x": float, "y": float, "angle": float,
"w": float, "h": float, "bbox": list[list[float]],
},
} | None,
}
Input Rules
maskmust be a 2Dnumpy.ndarray- Allowed values are
boolor numeric{0, 1} - Floating masks must not contain
NaNorinf - Empty mask returns
None - Shape and center arguments use image order:
(height, width)and(y, x)
Utilities
Mask constructors:
pm.utils.create_circle_mask(...)pm.utils.create_ellipse_mask(...)pm.utils.create_rectangle_mask(...)pm.utils.create_square_mask(...)pm.utils.create_triangle_mask(...)pm.utils.create_pentagon_mask(...)pm.utils.create_star_mask(...)pm.utils.create_particle_mask(...)
Visualization:
pm.utils.plot_analysis_results(mask, results)
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file partimorph-0.1.5.tar.gz.
File metadata
- Download URL: partimorph-0.1.5.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17ce40bcd78de02e3e7bd85369dad29eb1c2bf429e653d73f6947f7922688e44
|
|
| MD5 |
66974e63117d658e0fe3d8fd27627971
|
|
| BLAKE2b-256 |
fe751cb683a01bff6473c661a93edeb5058daf170def92237d0ad027c3182682
|
File details
Details for the file partimorph-0.1.5-py3-none-any.whl.
File metadata
- Download URL: partimorph-0.1.5-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cec51e0d162cc4fcbf9b4d3dc2139701ee445ea6514e9587d74ed275b72d33c
|
|
| MD5 |
ce81802da58cf373557d20b1ba577395
|
|
| BLAKE2b-256 |
73a5c799d5792d5800541ded335a806413f387f6335e2f2ec3a680e8b9b97eb8
|