Announcing Regions.jl — run-length encoded 2D regions for machine vision and image processing

I’m happy to announce Regions.jl, a package that introduces a first-class region type for discrete 2D image analysis, now registered in the Julia General Registry.

What is a region?

A region is a set of discrete 2D pixel positions represented as a run-length encoding (RLE). Instead of storing or iterating over individual pixels, Regions.jl tracks contiguous vertical runs of active pixels. This seemingly simple representation unlocks two major advantages for machine vision workflows:

  • Binary morphology without touching every pixel. Dilation, erosion, and related operations work on runs rather than on the full image array, yielding substantial speedups — on sparse industrial images, typically orders of magnitude faster than pixel-array approaches.
  • Efficient blob analysis. Connected-component labeling and shape feature extraction (area, centroid, bounding box, …) all exploit the run-length structure, so computation scales with the number of runs, not with the image area.

Quick taste

using Regions, Images, FileIO

img    = load("test/gear.png")
region = binarize(img, px -> px < 0.9)
blob   = argmax(area, components(region))   # pick the largest connected component

l, t, r, b = bounds(blob)     # bounding box
cc, cr     = centroid(blob)   # area-weighted centroid

No manual pixel loops needed — the region abstraction takes care of the bookkeeping.

Status

The package is at v0.5.0 and is MIT-licensed. Feedback, bug reports, and contributions are very welcome!