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

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page