Skip to main content

RLEMaskLib: Run-Length Encoded Mask Operations

Read the Docs PyPI - Version License: MIT

Fast run-length encoded (RLE) binary mask operations in Python. Core implemented in C via Cython for efficiency.

The API is designed to feel like NumPy and OpenCV, with familiar slicing, boolean operators, and method names.

Fully compatible with the COCO mask format.

Installation

pip install rlemasklib

Quick Start

import numpy as np
from rlemasklib import RLEMask

# Create from numpy array
mask = RLEMask(np.array([
    [0, 1, 1],
    [1, 1, 0],
    [0, 0, 1]
]))
mask1 = RLEMask.from_array(np.eye(3, dtype=np.uint8))
mask2 = RLEMask.from_array(np.eye(3, dtype=np.uint8)[::-1])

# Boolean operations
union = mask1 | mask2
intersection = mask1 & mask2
difference = mask1 - mask2
complement = ~mask

# Morphology
eroded = mask.erode3x3()
dilated = mask.dilate3x3()

# Geometric transforms (NumPy/OpenCV style)
flipped = mask.fliplr()
rotated = mask.rot90()
cropped = mask[10:50, 20:80]  # slicing like numpy
resized = mask.resize((256, 256))

# Analysis
area = mask.area()
bbox = mask.bbox()
components = mask.connected_components()

# COCO format I/O
coco_dict = mask.to_dict()  # {'size': [h, w], 'counts': b'...'}
mask = RLEMask.from_dict(coco_dict)

Features

  • Boolean operations: union, intersection, difference, complement, XOR, custom functions
  • Morphology: erode, dilate, open, close (circle/square/diamond/cross kernels of any size)
  • Geometric: crop, pad, tile, flip, transpose, rotate, resize, warp (affine/perspective)
  • Analysis: area, bounding box, connected components, largest interior rectangle, IoU
  • I/O: COCO format, numpy arrays, polygons, bounding boxes, circles
  • Compression: LEB128 (COCO-compatible) + optional gzip (~40% smaller)

APIs

Object-oriented (recommended): Work with RLEMask objects for chained operations.

Functional (legacy): Dict-to-dict operations, compatible with COCO's pycocotools.mask.

Documentation

Full documentation with visual examples: rlemasklib.readthedocs.io

Origin

Fork of COCO API's pycocotools.mask (by Piotr Dollár and Tsung-Yi Lin), now mostly new code.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rlemasklib-0.8.0.tar.gz (760.8 kB view details)

Uploaded Source

Built Distributions

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

rlemasklib-0.8.0-cp313-cp313-win_amd64.whl (494.4 kB view details)

Uploaded CPython 3.13Windows x86-64

rlemasklib-0.8.0-cp313-cp313-manylinux_2_28_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

rlemasklib-0.8.0-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rlemasklib-0.8.0-cp312-cp312-win_amd64.whl (492.2 kB view details)

Uploaded CPython 3.12Windows x86-64

rlemasklib-0.8.0-cp312-cp312-manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

rlemasklib-0.8.0-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rlemasklib-0.8.0-cp311-cp311-win_amd64.whl (503.0 kB view details)

Uploaded CPython 3.11Windows x86-64

rlemasklib-0.8.0-cp311-cp311-manylinux_2_28_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

rlemasklib-0.8.0-cp311-cp311-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

rlemasklib-0.8.0-cp310-cp310-win_amd64.whl (501.1 kB view details)

Uploaded CPython 3.10Windows x86-64

rlemasklib-0.8.0-cp310-cp310-manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

rlemasklib-0.8.0-cp310-cp310-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file rlemasklib-0.8.0.tar.gz.

File metadata

  • Download URL: rlemasklib-0.8.0.tar.gz
  • Upload date:
  • Size: 760.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for rlemasklib-0.8.0.tar.gz
Algorithm Hash digest
SHA256 c4ec6721fcc00f41e5de2f253c995a78f89af17006029a779d8aceb34ce137da
MD5 78d2d74e8d464637a458243bb0c51edf
BLAKE2b-256 33922fee088ee7a3ada1b36756117c2e6739d7f47ea375b616e5fa0a05590a93

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0.tar.gz:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: rlemasklib-0.8.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 494.4 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for rlemasklib-0.8.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6cffbd71ffd2e138d4ddd731e798a309fdb103e09d8378cedc51ee94d0669255
MD5 522ae84e902aeb6985d146355a741086
BLAKE2b-256 7a35c118e0a1576ee7400a850eee6af77a1ee6ed8515e836d82e3f2c49967b2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp313-cp313-win_amd64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rlemasklib-0.8.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 30254ead8ea5f11f7a484286d3a5228325ecd5e33ed214528d5cf2447cd2f0ca
MD5 63bb985bbec8f3dbcb643fb202500f12
BLAKE2b-256 2506d2f2c6f4b776b24edb6c782887f08a5d985a73dcecd8d1d97071622eb7af

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rlemasklib-0.8.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 670ce7b12513c1939d255971375e612ec7d0baafe87892ee3b91fadfa93e4c63
MD5 f66d1a80fdc2c275244f0610c1071f4f
BLAKE2b-256 1b226205117ba8eaba209535ce59e6e51a43717a1c4e1ec3bc90f8ef34b4b7ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: rlemasklib-0.8.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 492.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for rlemasklib-0.8.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 205fde80c402534aa286e1743eadf420e42f318396168ac335b7201203948d74
MD5 a14ec5c175d586064f9fc075acc5d50b
BLAKE2b-256 d3f1408e5b37ca99eb361c3598db2464d01d57351cf011172ef1a6e1266b29b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp312-cp312-win_amd64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rlemasklib-0.8.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0d120298d1cbbb542e42b5f7c0533c31ade382b35689c7d43ee834769c55e70c
MD5 f456bdb233a10e2c30e43972dca3c4d1
BLAKE2b-256 513dba1d243f30701fe8b0f9ab59c918dc7a7428a730cec98e67939a0b53086d

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rlemasklib-0.8.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 629cb5ba1c454ea81216ab698a89a86278d25877ba337083416d7be3d8988a5f
MD5 aa05132a19df090307f61a9132156504
BLAKE2b-256 3e63e8bc30ee5a113e9fcf6bcf7e63ac45638a6eb2b3aa77e2de5cd209034334

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: rlemasklib-0.8.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 503.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for rlemasklib-0.8.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fcc3ecc0c67fb9b0ad8d2a1be49ffaaa721b095911103bd2ba93621f991a431e
MD5 d81a2d0fe98da8a96308f23c7186cf2a
BLAKE2b-256 895e547e5dfd4b6f762c6367c10805c52f1a5c33d3ab9f1f8840cc8d869053ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp311-cp311-win_amd64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rlemasklib-0.8.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 241a4415c99b6d596c9d27d4fcf058440cf36b085b757caf264163c0348e144e
MD5 a46f71087308b9e1414e4acbd0796297
BLAKE2b-256 4d92630c4ed3bc2f560a087ccff4b3041b6e76648783ca62d830749abe57c791

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rlemasklib-0.8.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a138b78fcbc69fac54be83aac858a756eaa7442826a4299206eab8b1938e66e
MD5 f23a371c399e9f639090b448494476bd
BLAKE2b-256 d10896e9fea8e21a94df652450ca171f5d48f044a7c993bd773ff9b1ff82c06f

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: rlemasklib-0.8.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 501.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for rlemasklib-0.8.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2cb95da2e89dd7d336520b87594bd655ebf7d09019bffe1c1ecbb98af75c206f
MD5 d2ed388690d7997b0c23f27af312c4ef
BLAKE2b-256 d9835aebdffb0122e22b968a4a3f88789360feb32c438f5ff05d46669b0a3404

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp310-cp310-win_amd64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rlemasklib-0.8.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b6bbafb3162314d1726584b426a726a3bdf590d8e035b46145108565cdf47edc
MD5 f44cb793a70ec1a908752a8d416afe87
BLAKE2b-256 9eb5e7eb2015f725f7ba6391371ae12efb5d8307eebed5293c266696a192ba13

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

File details

Details for the file rlemasklib-0.8.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rlemasklib-0.8.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7d29d6b0ab73912d813aac16905dd164e7e6f89f937a41e7a5880b294d7c7dfb
MD5 25d42e063dd41b9b648e4b772c972abb
BLAKE2b-256 107a90bef9079242a3c1d3127a7bc5f756e7f77524d308fe22abd6e2a3eb00d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for rlemasklib-0.8.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on isarandi/rlemasklib

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

Release history Release notifications | RSS feed

This release

0.8.0 This release

13 files

0.7.0

19 files

0.6.1

19 files

0.6.0

19 files

0.5.0

31 files

0.4.0

26 files

0.3.15

1 file

0.3.14

1 file

0.3.13

1 file

0.3.12

1 file

0.3.4

1 file

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

0.0.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page