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:
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:
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:
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:
Project details
Release history Release notifications | RSS feed
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 details)
Built Distribution
tbcm-0.3-py3-none-any.whl
(7.3 kB
view details)
File details
Details for the file tbcm-0.3.tar.gz
.
File metadata
- Download URL: tbcm-0.3.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca1eb241b28d8df2e6c263e8325ef91c680bd2b1f56eeeca48c8805e60eacb70 |
|
MD5 | 93dde3e647dd545cf04abe806c429e74 |
|
BLAKE2b-256 | 41c83a39cb3c7b57f40844bf24effe247f98d56cf178d235779b8b1329cb8ac8 |
File details
Details for the file tbcm-0.3-py3-none-any.whl
.
File metadata
- Download URL: tbcm-0.3-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cd2d72e8061f7dba894c9ebfc082f5d13f6022a07390b77121871c7ed9f53c2 |
|
MD5 | d496a297517277232e89893b779120bd |
|
BLAKE2b-256 | 01dcf2c16250ac23bab797eb369f965e517b3881fdb58cdea341e79df0d55cd8 |