Skip to main content

License: MIT Generic badge DOI

Grayscale to Color Semantic Mask Converotr

Bug Fixes

version 0.4.3

  • updated for use with pytorch and numpy.
  • added deepglob dataset pallet.

version 0.4.1

Fixed ValueError raised while using Custom color pallet.

Dependencies

numpy
cv2
tensorflow # only if using backend='tf'
python >= 3.6

Installation

pip install gray2color

This lib converts the grayscale semantic masks obtained at the output a CNN and fills it with colors for example in case of cityscape dataset you have 30 channels at the output of CNN and after using argmax to create one channel semantic mask you get the following output

alt text which you can use for measuring IOU, Dice or other evaluation metrics. But it is a bit difficult for human visualization so this package converts the above output to following ouptut easy to visualize. alt text

Usage

import cv2
from gray2color import gray2color

'''
two backends
'tf' # for tesnorflow
'np' # for numpy/pytorch
'''
mask = cv2.imread('../gray.png', 0)
rgb = gray2rgb(mask, use_pallet='cityscape', custom_pallet=None, backend='np')

Returns

A uint8 image with values ranging from [0, 255] you can save via

import cv2

rgb = cv2.cvtColor(rgb, cv2.COLOR_BGR2RGB)  #   becaues cv2 will change color channels before writing
cv2.imwrite('../rgb.png', rgb)

Available Pallets

Available Pallets are ade20k, cityscape, lip, pannuke, pascal, vistas for details on all above pallets and their corresponding names visit here

Usage with custom pallets

You can also define your custom color Pallets as follows

# values are in order [R, G, B] ranging from [0, 255]

c_pallet = np.array([[[128, 64, 128],
                    [244, 35, 232],
                    [70, 70, 70],
                    [102, 102, 156],
                    [190, 153, 153]]], np.uint8) / 255
rgb = gray2rgb(mask, use_pallet=None, custom_pallet=c_pallet, backend='np')

Raises Errors

PalletNotDefined: if pallet is not specified

NotEnoughColors: if grayscale mask has more classes present than the colors in the pallet

For more details visit GitHub

Metadata

Release files for gray2color 0.4.3

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

Source distribution (sdist)

Source distribution for gray2color 0.4.3
File Size Uploaded
gray2color-0.4.3.tar.gz 10.5 kB Details

Release files / gray2color-0.4.3.tar.gz

Download URL gray2color-0.4.3.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
151f7594bdc46a340e9e9bb85841086a7b3b8821b561ccc6604e1e14c773b5cc
BLAKE2b-256 checksum
How to use checksums
824fc38ab8611cb07ecf86bfcb7ed4f31541fbff821a6f4a32421d70f4f58e43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.4.3 This release

1 release file

0.4.1

2 release files

0.4.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.1

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