Skip to main content

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 Particle bounds larger than this are downscaled for speed, then coordinates are restored

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

  • mask must be a 2D numpy.ndarray
  • Allowed values are bool or numeric {0, 1}
  • Floating masks must not contain NaN or inf
  • Empty mask returns None
  • The largest connected foreground component is selected and holes are filled
  • Surrounding zero padding does not change the measured shape
  • Downscaling is skipped if its output would have a one-pixel axis
  • Shape and center arguments use image order: (height, width) and (y, x)

Project Layout

  • analyzer.py: public analysis workflow and result-coordinate restoration
  • validation.py: public input normalization and analysis-option validation
  • mask_ops.py: component selection, crop/resize transforms, and contours
  • metrics.py: metric formulas and public result payloads
  • fitting.py: circle and ellipse fitting plus oriented bounding boxes
  • wadell/: boundary, smoothing, discretization, and corner roundness stages
  • utils/: synthetic mask construction and visualization

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

Metadata

Release files for partimorph 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for partimorph 0.1.7
File Size Uploaded Provenance Actions
partimorph-0.1.7.tar.gz 19.9 kB Without provenance Details for partimorph-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for partimorph 0.1.7
File Interpreter ABI Platform Actions
partimorph-0.1.7-py3-none-any.whl Python 3 none any Details for partimorph-0.1.7-py3-none-any.whl

Total release size: 39.5 kB

Release files / partimorph-0.1.7.tar.gz

Download URL partimorph-0.1.7.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
efd4a9635474b29017b1ab07dc405e4fde23f76dbeadc5ac29e73a7d9654f4ed
BLAKE2b-256 checksum
How to use checksums
495df1099ce3b55514614f46d25102aea7faf6fb4e5dce6539af790d2ff11e3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Release files / partimorph-0.1.7-py3-none-any.whl

Download URL partimorph-0.1.7-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd02e6c8bc01074dbbb633f0b459c0e55f97ef9722d892fd8bf7ccde446fae09
BLAKE2b-256 checksum
How to use checksums
8b99fd5edc437c532cdc0a8abb1a738703d9e2c5b9c82c9fe2d3d52c45fdfd24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Security for partimorph 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page