Skip to main content

Segmentation mask overlay

If you ever wonder to overlay your segmentations onto a picture in the smoothiest way, you're in a right place.

Installation

pip install segmentation-mask-overlay

Description

Here you can take your segmentation map, put on an image individually or in a company. If you have a bunch of them, they will blend if touch each other.

You can even name them one by one, providing labels.

That's it! As simple as is. Now you are completely ready to laminate images with your segmentation.

How to use

import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
from segmentation_mask_overlay import overlay_masks

# [Example] Load image
image = Image.open("cat.jpg").convert("L")
image = np.array(image)

# [Example] Mimic list of masks
masks = []
for i in np.linspace(0, image.shape[1], 10, dtype="int"):
    mask = np.zeros(image.shape, dtype="bool")
    mask[i : i + 100, i : i + 200] = 1
    masks.append(mask)

# [Optional] prepare labels
mask_labels = [f"Mask_{i}" for i in range(len(masks))]

# [Optional] prepare colors
cmap = plt.cm.tab20(np.arange(len(mask_labels)))[..., :-1]

# Laminate your image!
fig = array = overlay_masks(image, np.stack(masks, -1), mask_labels, return_type="mpl")

# Do with that image whatever you want to do.
fig.savefig("cat_masked.png", bbox_inches="tight", dpi=300)

Segmented cat

CHANGELOG

  • v0.4.4:
    • Dropped mandatory label arg in overlay_masks()
    • Added one-channel binary masks handling in overlay_masks()

Metadata

Release files for segmentation-mask-overlay 0.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for segmentation-mask-overlay 0.4.4
File Size Uploaded
segmentation-mask-overlay-0.4.4.tar.gz 279.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for segmentation-mask-overlay 0.4.4
File Interpreter ABI Platform
segmentation_mask_overlay-0.4.4-py3-none-any.whl Python 3 none any Details

Total release size: 289.3 kB

Release files / segmentation-mask-overlay-0.4.4.tar.gz

Download URL segmentation-mask-overlay-0.4.4.tar.gz
Size 279.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5ee821b153f829ceefcadc0fa042284afc97657963994c5acbc65c60ff89d640
BLAKE2b-256 checksum
How to use checksums
3f5d49adde17b4aaafd0a3e1b52d70e66023366c0c8aac1256222e513c824c16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.11.3 pkginfo/1.8.3 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.10.8

Release files / segmentation_mask_overlay-0.4.4-py3-none-any.whl

Download URL segmentation_mask_overlay-0.4.4-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c28112b2da01db1a00b048838182766c097e88255dcd7b2206aef24732e76526
BLAKE2b-256 checksum
How to use checksums
ec7400adf089539754bc9cc6fd1a2f5b9b20776b2dca82e7193b32c6ae1434d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.11.3 pkginfo/1.8.3 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.10.8

Release history Release notifications | RSS feed

This release

0.4.4 This release

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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