Skip to main content

Particle shape analysis and visualization library.

Project description

PartiMorph

2D binary particle shape analysis library. Computes four morphological metrics from a binary mask:

  • Wadell roundness — corner curvature-based roundness
  • ISO circularity — perimeter-area ratio
  • Riley sphericity — inscribed/enclosing circle ratio
  • Aspect ratio — fitted ellipse major/minor axis ratio

All values are dimensionless ratios (0–1, except aspect ratio which is >= 1).

Installation

Python 3.12+

pip install partimorph

Quick Start

import partimorph as pm

mask = pm.utils.create_circle_mask((256, 256), (128, 128), 60)
results = pm.analyze_mask(mask)

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

Returns an AnalysisResult dict. Keys are only present for enabled metrics (use_*=True).

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: bool or {0, 1}
  • Empty mask returns None

Utilities

  • pm.utils.create_particle_mask(...) — synthetic mask generator with Fourier roughness control
  • pm.utils.plot_analysis_results(mask, results) — overlay visualization of all computed metrics

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

partimorph-0.1.1.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

partimorph-0.1.1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file partimorph-0.1.1.tar.gz.

File metadata

  • Download URL: partimorph-0.1.1.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for partimorph-0.1.1.tar.gz
Algorithm Hash digest
SHA256 087af718afbd2ba0a7931a07b89d0e01b1a60a0ce96b19c95706353de7c8043d
MD5 9270d007f781ba0511fb7ea5259c2aba
BLAKE2b-256 9cd502f6c372cafe365075c6e5beb1a98a0d5529a15ebf1c2bd63fe8e38bdfc9

See more details on using hashes here.

File details

Details for the file partimorph-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: partimorph-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for partimorph-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a4939c52b233bbe1fae09edc18d06b5f0be16d30fe9de2b5f191f72d6513d2d5
MD5 dd11edd6659759ce4099570482ef0ca5
BLAKE2b-256 49ac9dfcb30dd7b93011e132fa984092ae9d7dc59f9172685a4937e2f20fe263

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page