Skip to main content

Use Matplotlib colormaps with OpenCV in Python.

Project description

cmapy

Use Matplotlib colormaps with OpenCV in Python.

Matplotlib provides a lot of nice colormaps. Cmapy exposes these colormaps as lists of colors that can be used with OpenCV to colorize images or for other drawing tasks in Python.

Original image
viridis

See all of the available colormaps as of Matplotlib 2.2.3 in this all colormaps example.

Requirements

  • Python 2.7 or 3.
  • Matplotlib.
  • OpenCV >= 3.3.0 (to use cv2.applyColorMap()).

Installation

Python 2.7, with pip:

pip install cmapy

Python 3.x, with pip:

pip3 install cmapy

Or, in a Conda environment:

conda install -c conda-forge cmapy 

How to use

Colorize images

Colorize means to apply a colormap to an image. This is done by getting the colormap with cmapy.cmap() and then applying cv2.applyColorMap(), like this:

img_colorized = cv2.applyColorMap(img, cmapy.cmap('viridis'))

Alternatively, you can use cmapy.colorize() directly:

img_colorized = cmapy.colorize(img, 'viridis')

See the full colorize example.

Draw with colors

Use the cmapy.color() function and an index between 0 and 255 to get a color from a colormap. Cmapy.color() returns a list of BGR (or RGB) values that can be used with OpenCV drawing functions.

# Get color in BGR order (default) by index.
bgr_color = cmapy.color('viridis', 127)

# Get color in RGB order with a float value.
rgb_color = cmapy.color('viridis', 0.5, rgb_order=True)

See a complete drawing with colors example.

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

cmapy-0.4.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file cmapy-0.4.tar.gz.

File metadata

  • Download URL: cmapy-0.4.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15rc1

File hashes

Hashes for cmapy-0.4.tar.gz
Algorithm Hash digest
SHA256 d51fa6d2e4b671b680db1e7bef5eaf96654f5397ff94f69f6227b1a4dd2d8408
MD5 d4b7b8e427542ebf77a81df05834e81a
BLAKE2b-256 431416d8d2979a9e8402ac42d12c4697b8e409a48d6a34d9126ae7b7ca104550

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