Skip to main content

Ten Bit Color Maps

Project description

Ten Bit Color Maps

Features

  • 1024 colors in each sequential colormap
  • Perceptually uniform - each color is same perceptual distance from the previous color (before rounding)
  • Raw color data rounded so they can be used in a byte tensor (see pytorch example below)
  • All maps start at black

Installation

pip install tbcm

Usage

With matplotlib

from tbcm import tb_inferno, tb_oleron

then to use tb_inferno, do:

import matplotlib.pyplot as plt
import numpy as np
x,y = np.meshgrid(np.linspace(-1,1,15),np.linspace(-1,1,15))
z = np.cos(x*np.pi)*np.sin(y*np.pi)

fig = plt.figure(figsize=(9,4))
ax1 = fig.add_subplot(121, projection='3d')
ax1.plot_surface(x,y,z,rstride=1,cstride=1,cmap=tb_inferno)
ax2 = fig.add_subplot(122)
cf = ax2.contourf(x,y,z,51,vmin=-1,vmax=1,cmap=tb_inferno)
cbar = fig.colorbar(cf)

result:

matplotlib tb_inferno example

and the same with tb_oleron is:

fig = plt.figure(figsize=(9,4))
ax1 = fig.add_subplot(121, projection='3d')
ax1.plot_surface(x,y,z,rstride=1,cstride=1,cmap=tb_oleron)
ax2 = fig.add_subplot(122)
cf = ax2.contourf(x,y,z,51,vmin=-1,vmax=1,cmap=tb_oleron)
cbar = fig.colorbar(cf)

result:

matplotlib tb_inferno example

With pytorch

from tbcm import tb_inferno_data, tb_oleron_data

import torch
tb_inferno_cm = torch.tensor(tb_inferno_data, dtype=torch.uint8)
tb_oleron_cm = torch.tensor(tb_oleron_data, dtype=torch.uint8)

then to use tb_inferno, do:

from PIL import Image

z = torch.cos(torch.linspace(-1, 1, 256).view(1, -1) * torch.pi) * torch.sin(
    torch.linspace(-1, 1, 256).view(-1, 1) * torch.pi)
z.add_(1).div_(2)

h,w = z.shape
idx = z.view(-1).mul(1023).round().clamp(0,1023).long()
img = tb_inferno_cm[idx].view(h,w,3)
Image.fromarray(img.numpy())

result:

pytorch tb_inferno example

and the same with tb_oleron:

h,w = z.shape
idx = z.view(-1).mul(1023).round().clamp(0,1023).long()
img = tb_oleron_cm[idx].view(h,w,3)
Image.fromarray(img.numpy())

result:

pytorch tb_oleron 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

tbcm-0.3.tar.gz (8.2 kB view hashes)

Uploaded Source

Built Distribution

tbcm-0.3-py3-none-any.whl (7.3 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