• Stars
    star
    285
  • Rank 144,302 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A header-only, single-file library for colormaps written in C++11

tinycolormap

macOS Ubuntu GitHub

A header-only, single-file library for colormaps written in C++11.

Available Colormaps

Matlab

Name Sample
Parula
Heat
Hot
Jet
Gray
HSV

Reference: https://www.mathworks.com/help/matlab/ref/colormap.html

The HSV colormap is cyclic and is particularly useful for plotting angles or phases because the color transition from 1 to 0 is smooth. A phase wrap would thus not appear as a sharp edge.

Matplotlib

Name Sample
Magma
Inferno
Plasma
Viridis
Cividis

These colormaps are designed to be perceptually uniform (even in black-and-white printing) and friendly to colorblindness. Cividis is specially designed such that it enables as identical interpretation to both those without a CVD and those with red-green colorblindness as possible.

Magma, Inferno, Plasma, Viridis are released under CC0 by Nathaniel J. Smith, Stefan van der Walt, and (in the case of Viridis) Eric Firing: https://github.com/BIDS/colormap/blob/master/colormaps.py. Their python code is adapted for the use in C++11.

Cividis is released under CC0 by the authors of PLOS ONE paper (Jamie R. Nuñez, Christopher R. Anderton, Ryan S. Renslow): https://doi.org/10.1371/journal.pone.0199239. We incorporated the LUT into C++11.

GitHub

Name Sample
Github

This colormap is designed to mimic the color scheme used in GitHub contributions visualization.

Other

Name Sample
Turbo

Turbo is developed as an alternative to the Jet colormap by Anton Mikhailov (Google LLC). See the blog post for the details. The original lookup table is released under the Apache 2.0 license. We merged it and re-licensed the part under the MIT license for consistency.

Name Sample
Cubehelix

Cubehelix is developed by Dr. Dave Green and is designed for astronomical intensity images. It shows a continuous increase in perceived intensity when shown in color or greyscale. This implementation uses Green's "default" scheme (start: 0.5, rotations: -1.5, hue: 1.0, gamma: 1.0). See the original publication for details.

Dependency

tinycolormap does not have any dependencies except for C++11 standard library.

Installation

tinycolormap is a header-only library, so you do not need to compile it. You can use it by

  • Adding the path to the include directory in the cloned tinycolormap repository to your project's include paths, or
  • Copying the file tinycolormap.hpp to your project (note that tinycolormap consists of only that single file).

If your project is managed by Cmake https://cmake.org/, add_subdirectory or ExternalProject_Add commands are useful as tinycolormap provides CMakeLists.txt for this purpose.

Usage

The core function of this library is

inline Color GetColor(double x, ColormapType type);

where x should be between 0.0 and 1.0 (otherwise, it will be cropped), and type is the target colormap type like Viridis (default) and Heat.

Here is a working code:

#include <iostream>
#include <tinycolormap.hpp>

int main()
{
  // Define a target value. This value should be in [0, 1]; otherwise, it will be cropped to 0 or 1.
  const double value = 0.5;

  // Get the mapped color. Here, Viridis is specified as the colormap.
  const tinycolormap::Color color = tinycolormap::GetColor(value, tinycolormap::ColormapType::Viridis);

  // Print the RGB values. Each value is in [0, 1].
  std::cout << "r = " << color.r() << ", g = " << color.g() << ", b = " << color.b() << std::endl;

  return 0;
}

Quantized colors

tinycolormap is also capable of producing quantized colormaps (i.e. the ones that have visible boundaries between colors) based on the user specified number of levels. Below is the example of the quantized Parula colormap using 10 quantization levels:

Name Sample
Parula

Note that the supported range for number of levels is [1, 255].

Here is an example code that uses colormap quantization:

int main()
{
  // Define a target value. This value should be in [0, 1]; otherwise, it will be cropped to 0 or 1.
  const double value = 0.5;

  // Define number of levels for the colormap quantization. This value should be in [1, 255]; otherwise, it will be cropped to 1 or 255.
  const unsigned int num_levels = 10;

  // Get the mapped color. Here, Parula is specified as the colormap.
  const tinycolormap::Color color = tinycolormap::GetQuantizedColor(value, num_levels, tinycolormap::ColormapType::Parula);

  // Print the RGB values. Each value is in [0, 1].
  std::cout << "r = " << color.r() << ", g = " << color.g() << ", b = " << color.b() << std::endl;

  return 0;
}

Options for External Libraries Integration

Qt5 Support

When TINYCOLORMAP_WITH_QT5 is defined before including tinycolormap.hpp, for example,

#define TINYCOLORMAP_WITH_QT5
#include <tinycolormap.hpp>

(or TINYCOLORMAP_WITH_QT5 CMake option is ON), this library offers an additional utility function:

const QColor color = tinycolormap::GetColor(x).ConvertToQColor();

Eigen Support

When TINYCOLORMAP_WITH_EIGEN is defined before including tinycolormap.hpp, for example,

#define TINYCOLORMAP_WITH_EIGEN
#include <tinycolormap.hpp>

(or TINYCOLORMAP_WITH_EIGEN CMake option is ON), this library offers an additional utility function:

const Eigen::Vector3d color = tinycolormap::GetColor(x).ConvertToEigen();

Qt5 and Eigen Support

When both Qt5 and Eigen are available, this library offers additional utility functions:

inline QImage CreateMatrixVisualization(const Eigen::MatrixXd& matrix);
inline void ExportMatrixVisualization(const Eigen::MatrixXd& matrix, const std::string& path);

GLM Support

When TINYCOLORMAP_WITH_GLM is defined before including tinycolormap.hpp, for example,

#define TINYCOLORMAP_WITH_GLM
#include <tinycolormap.hpp>

(or TINYCOLORMAP_WITH_GLM CMake option is ON), this library offers an additional utility function:

const glm::vec3 color = tinycolormap::GetColor(x).ConvertToGLM();

Tools (Optional)

This repository includes the following optional tools:

  • PNG Exporter: This tool exports all the available colormaps as PNG images.

Tools Build Instruction

The optional tools are managed by CMake https://cmake.org/. They can be built by, for example,

mkdir build
cd build
cmake [PATH_TO_TINYCOLORMAP] -DTINYCOLORMAP_BUILD_TOOLS=ON
make

Projects using tinycolormap

License

The MIT License (except for tools/png-exporter/stb_image_write.h, which is released under public domain).

Contribute

Pull requests are welcome.

More Repositories

1

blender-cli-rendering

Blender Python scripts for rendering images directly from command-line interface
Python
692
star
2

elasty

A research-oriented elastic body simulator
C++
323
star
3

mathtoolbox

Mathematical tools (interpolation, dimensionality reduction, optimization, etc.) written in C++11 with Eigen
C++
245
star
4

bigger

bigg (bgfx + imgui + glfw + glm) + utils
C++
196
star
5

unblending

Decomposing an input image into layers via "color unblending"
C++
162
star
6

position-based-fluids

Position Based Fluids [SIGGRAPH 2013] in C++
C++
125
star
7

color-util

A header-only C++11 library for colors; color space converters for RGB, HSL, XYZ, Lab, etc. and perceptual color difference calculators such as CIEDE2000
C++
89
star
8

sequential-line-search

A Preferential Bayesian optimization library for C++/Python [SIGGRAPH 2017]
C++
43
star
9

bvh11

A tiny C++11 library for reading BVH motion capture data
C++
36
star
10

optimo

Keyframe-based motion editing system using numerical optimization [CHI 2018]
C++
30
star
11

parallel-util

Simple header-only implementation of "parallel_for" and "parallel_map" for C++11
C++
30
star
12

btoon

Blender Addon for Toon Rendering
Python
21
star
13

sequential-gallery

Sequential Gallery for Interactive Visual Design Optimization [SIGGRAPH 2020]
C++
20
star
14

hello-bgfx

Hello-world project for bgfx + GLFW managed by CMake
C++
15
star
15

split-toning

A Blender addon for simulating the Split Toning effect in Adobe Lightroom/Photoshop
Python
14
star
16

real-time-example-based-elastic-deformation

Real-Time Example-Based Elastic Deformation [SCA 2012]
C
14
star
17

nlopt-util

A header-only wrapper library for calling NLopt optimization in a single line using Eigen::VectorXd
C++
14
star
18

visoptslider

Qt-based implementation of VisOpt Slider widget [UIST 2014] for C++ & Python
C++
12
star
19

nodelayout

A Blender add-on for automatic layout of nodes
Python
9
star
20

cc0assetsloader

A Blender add-on for loading CC0 assets (PBR textures, HDR images, etc.)
Python
8
star
21

enhancer

A C++11 / GLSL library for enhancing photographs (adjusting brightness, contrast, etc.)
C++
8
star
22

latexie

Utilities for writing papers with LaTeX
TeX
6
star
23

constrained-optimization-tests

Simple implementation of constrained optimization methods, including the penalty method and the augmented Lagrangian method
C++
5
star
24

rbf-interpolator

[deprecated] Radial Basis Function (RBF) Interpolation written in C++11. This can be used for fitting a non-linear function from scattered data.
C++
5
star
25

siggraph-jp-papers

SIGGRAPH Papers by Japanese Researchers
HTML
4
star
26

selph

Machine learning-based photo color enhancement system [CHI 2016]
C++
4
star
27

three-dim-util

A utility library for prototyping 3D applications based on Qt, Eigen, and legacy OpenGL
C++
4
star
28

armature-proxy-mesh

A Blender add-on for easy creation of proxy meshes for a selected armature object
Python
4
star
29

imagedistance

Given two images, calculate their distance in several criteria
C++
3
star
30

pycolormap

A self-contained colormap library for Python
Python
3
star
31

hello-tbb-cmake

A hello-world project for testing "parallel_for" in Intel TBB. The whole project (including TBB) is built using CMake.
C++
3
star
32

multidimensional-scaling

[deprecated] A header-only C++ library of the multidimensional scaling (MDS)
C++
2
star
33

academic-illustration-assets

Assets for creating illustrative figures (and video figures) released under CC0 (public domain)
2
star
34

filesystem-util

C++11 utility functions for handling files (currently only for UNIX/Linux)
C++
2
star
35

timer

Execution timer for measuring elapsed times for code blocks written in C++11
C++
1
star
36

cgi-2019-program

List of the papers presented at CGI 2019
Python
1
star
37

hello-alembic

Just a hello-world project to start learning the Alembic library
C++
1
star
38

pyenhancer

A tiny NumPy-based library for image color enhancement
Python
1
star
39

hello-trello-api

Toy Python scripts using Trello's REST API
Python
1
star
40

rand-util

Utility functions for <random> in c++11
C++
1
star
41

optimization-test-functions

A set of test functions to evaluate optimization algorithms written in C++11
C++
1
star
42

string-util

Utility functions for <string> in C++11
C++
1
star
43

qt-animated-layout-example

A custom animated layout example in Qt5
C++
1
star
44

easy-qhull

A helper repository to use qhull in cmake-based c++ projects
CMake
1
star