Skip to main content

Vectorized region-property features (skimage-compatible) via a single scatter pass.

Project description

fast-regionprops

A faster (vectorized) version of regionprops that supports a subset of region-property features, yielding a typical ~10–80× speedup (especially for many regions). Can be used as a drop-in replacement for skimage.measure.regionprops_table for the following set of properties:

label, area, centroid, bbox, equivalent_diameter_area,
intensity_mean, intensity_min, intensity_max, intensity_std,
inertia_tensor, border_dist
Dim Image size #Regions skimage (ms) fast (ms) Speedup
2D 512×512 100 10.5 0.4 26.8×
2D 512×512 400 40.8 0.5 77.8×
2D 1024×1024 1600 163.1 2.0 82.8×
2D 2048×2048 3600 368.7 6.5 57.0×
3D 128×128×128 512 76.5 3.3 23.5×
3D 256×256×256 1728 229.6 19.6 11.7×

Install

pip install fast-regionprops
# dev / tests
pip install -e ".[test]"
# dev / tests / pre-commit
pip install -e ".[dev]"
pre-commit install

Usage

import numpy as np
from skimage.data import binary_blobs
from skimage.measure import label

from fast_regionprops import regionprops_table_fast

# example data: blobs as mask, random image as intensity
mask = label(binary_blobs(length=512, blob_size_fraction=0.05, volume_fraction=0.1))
intensity = np.random.default_rng(0).random(mask.shape).astype("float32")

# drop-in for skimage.measure.regionprops_table (same column names)
table = regionprops_table_fast(
    mask,
    intensity,
    properties=("label", "area", "centroid", "intensity_mean", "inertia_tensor"),
)
table["centroid-0"], table["inertia_tensor-0-1"]   # 1D arrays, one row per label

Output is a dict[str, np.ndarray] (same as for skimage.measure.regionprops_table)

Property notes

  • Calling regionprops_table_fast(label_image) uses the same default properties as skimage.measure.regionprops_table: label and bbox.

  • label_image must be an integer 2D or 3D label image. Boolean and floating point inputs are rejected as ambiguous; labels <= 0 are ignored.

  • intensity_image may have the same shape as label_image, or one extra trailing channel axis. Multichannel intensity columns follow skimage naming, for example intensity_mean-0, intensity_mean-1.

  • border_dist is an extra property (not in skimage): the per-label max of a field that fades from 1 at the image border to 0 once border_dist_cutoff px away (last two axes only).

  • properties needing a convex hull / perimeter / topology (solidity, perimeter, euler_number, etc.) are not yet supported.

License

BSD-3-Clause.

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

fast_regionprops-0.1.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

fast_regionprops-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file fast_regionprops-0.1.0.tar.gz.

File metadata

  • Download URL: fast_regionprops-0.1.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fast_regionprops-0.1.0.tar.gz
Algorithm Hash digest
SHA256 869071dd0c41a798189ee3d17763c9c0c661e149625ec500207560756bc273bd
MD5 7c6b010df1ee4db9042bee6c073ff8c0
BLAKE2b-256 e9c0d95b70302dad9510c89b13b1575879f07e42ed5cadf55e4132e93fe08f9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_regionprops-0.1.0.tar.gz:

Publisher: publish.yml on maweigert/fast-regionprops

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast_regionprops-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fast_regionprops-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d6615b7065666a6ab3a43a12c881a188b21394c4b45b52fc1e196b935ac9dd2
MD5 b7271bf74a266aa920c6023bf433dc38
BLAKE2b-256 708de7e7a6e9ce0a19c2383890b443ced9caea11fddba3060883add111709582

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_regionprops-0.1.0-py3-none-any.whl:

Publisher: publish.yml on maweigert/fast-regionprops

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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