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.3.tar.gz (16.3 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.3-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: partimorph-0.1.3.tar.gz
  • Upload date:
  • Size: 16.3 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.3.tar.gz
Algorithm Hash digest
SHA256 9c5b00725458942a94ea303b204aeb43c5e21556fbf0d7b2e0728e78918e073d
MD5 a1d5ef5cae70eb5d03dc7c336b897103
BLAKE2b-256 7e4ffed26f45124b86bab521ca2a333f236fc4e660bfaeb69132d5315e257b5b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: partimorph-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 18.1 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cdc2d43a16cdf3f82c95724b2507de8c5398133ab6de47d8b7c902d37969c1c1
MD5 e815c6db979d3b060cf95d185ecc6a52
BLAKE2b-256 45c1a156bdcc1382a2e62a8fd3c8a4076379a10aa6c016c23b477b7172f403de

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