fastlabelops and fastlabelrle - fast CPU utilities for integer label arrays

Hi all,

I’ve recently released two small Python packages for working with large integer label arrays.

Both are CPU-only, expose NumPy-facing APIs, and have NumPy as their only runtime dependency.

fastlabelops

fastlabelops provides a small set of common operations on integer label images, implemented in C++:

  • relabel_sequential
  • remove_small_objects
  • basic regionprops such as area, bounding box, and centroid
  • label counting
  • sparse overlap / contingency counting between two label arrays

The goal is not to replace scikit-image, but to provide fast implementations of a few operations that can become expensive on large instance-label arrays or masks containing many objects.

In my benchmarks, some of these operations are substantially faster than equivalent NumPy/scikit-image workflows, particularly basic region-property computation and sparse overlap counting.

PyPI: fastlabelops · PyPI
GitHub: GitHub - ajinkya-kulkarni/fastlabelops: Fast CPU operations for instance masks. · GitHub

fastlabelrle

fastlabelrle converts an integer instance-label array directly into COCO-style RLEs.

A common approach is to iterate over labels, construct mask == label for each object, and then encode each binary mask individually. fastlabelrle avoids creating those per-instance intermediate masks.

For example, on a 2048×2048 label image containing 4096 instances, one benchmark gives approximately:

  • fastlabelrle: 35.7 ms
  • per-instance encoding using pycocotools: 84.9 s

The exact difference depends heavily on the label structure and workload, but the motivation is to make conversion of large instance-segmentation outputs to COCO RLE considerably cheaper.

PyPI: fastlabelrle · PyPI
GitHub: GitHub - ajinkya-kulkarni/fastlabelrle: Fast direct COCO RLE encoding for integer instance-label images. · GitHub

Both packages are intentionally narrow rather than general-purpose image-processing libraries.

They originally came out of microscopy/pathology instance-segmentation workflows, but the implementations themselves are generic and operate on NumPy integer label arrays.

I’d be interested in feedback from the Scientific Python community, particularly around benchmarking, edge cases, and whether there are other common label-array operations where a lightweight optimized implementation would be useful.