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.4.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.4-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: partimorph-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 de0cff33737b75d5a3a4dac00ae9db601168726aeec5f08b7e3d44a92a559bfb
MD5 5b412af70f98144f6b86f79002f6e4ba
BLAKE2b-256 41a2bd7bf9ac1f0bbd11b46542b6a39f1448703c3db19c82a62f88d8ce72794b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: partimorph-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c65e9feda3fa25207d1b65c3242f846d12e487c60bc9923005ca6999d103da26
MD5 d3bfb04c2a42afda1a691ec2048f8b32
BLAKE2b-256 da7b2266eca7ea7343ce0775a4d7274f1e7c192c22133066a41d6e0f5841230a

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