Skip to main content

Plotting the segmentation masks has never been so exciting!

Project description

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()

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

segmentation-mask-overlay-0.4.4.tar.gz (279.9 kB view details)

Uploaded Source

Built Distribution

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

segmentation_mask_overlay-0.4.4-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file segmentation-mask-overlay-0.4.4.tar.gz.

File metadata

  • Download URL: segmentation-mask-overlay-0.4.4.tar.gz
  • Upload date:
  • Size: 279.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for segmentation-mask-overlay-0.4.4.tar.gz
Algorithm Hash digest
SHA256 5ee821b153f829ceefcadc0fa042284afc97657963994c5acbc65c60ff89d640
MD5 c9dcfc8f6ffc6d9675d0f3383f471052
BLAKE2b-256 3f5d49adde17b4aaafd0a3e1b52d70e66023366c0c8aac1256222e513c824c16

See more details on using hashes here.

File details

Details for the file segmentation_mask_overlay-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: segmentation_mask_overlay-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for segmentation_mask_overlay-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c28112b2da01db1a00b048838182766c097e88255dcd7b2206aef24732e76526
MD5 0a5f0549abab7d93a5e490817e6805b6
BLAKE2b-256 ec7400adf089539754bc9cc6fd1a2f5b9b20776b2dca82e7193b32c6ae1434d9

See more details on using hashes here.

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