Skip to content

Commit

Permalink
Added cubehelix.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaseDurand committed Jan 25, 2022
1 parent ea77a2b commit 8d58a26
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ This colormap is designed to mimic the color scheme used in GitHub contributions

Turbo is developed as an alternative to the Jet colormap by Anton Mikhailov (Google LLC). See [the blog post](https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html) for the details. [The original lookup table](https://gist.github.com/mikhailov-work/6a308c20e494d9e0ccc29036b28faa7a) 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 | ![](docs/samples/Cubehelix.png) |

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 origial publication](https://ui.adsabs.harvard.edu/abs/2011BASI...39..289G/abstract) for details.

## Dependency

tinycolormap does not have any dependencies except for C++11 standard library.
Expand Down
Binary file added docs/samples/Cubehelix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
270 changes: 269 additions & 1 deletion include/tinycolormap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace tinycolormap

enum class ColormapType
{
Parula, Heat, Jet, Turbo, Hot, Gray, Magma, Inferno, Plasma, Viridis, Cividis, Github
Parula, Heat, Jet, Turbo, Hot, Gray, Magma, Inferno, Plasma, Viridis, Cividis, Github, Cubehelix
};

struct Color
Expand Down Expand Up @@ -138,6 +138,7 @@ namespace tinycolormap
inline Color GetViridisColor(double x);
inline Color GetCividisColor(double x);
inline Color GetGithubColor(double x);
inline Color GetCubehelixColor(double x);

#if defined(TINYCOLORMAP_WITH_QT5) && defined(TINYCOLORMAP_WITH_EIGEN)
inline QImage CreateMatrixVisualization(const Eigen::MatrixXd& matrix);
Expand Down Expand Up @@ -223,6 +224,8 @@ namespace tinycolormap
return GetCividisColor(x);
case ColormapType::Github:
return GetGithubColor(x);
case ColormapType::Cubehelix:
return GetCubehelixColor(x);
default:
break;
}
Expand Down Expand Up @@ -2166,6 +2169,271 @@ namespace tinycolormap
return internal::CalcLerp(x, data);
}

inline Color GetCubehelixColor(double x)
{
constexpr Color data[] =
{
{ 0.000000, 0.000000, 0.000000 },
{ 0.006716, 0.002119, 0.005970 },
{ 0.013252, 0.004287, 0.012162 },
{ 0.019599, 0.006514, 0.018563 },
{ 0.025748, 0.008803, 0.025162 },
{ 0.031691, 0.011164, 0.031946 },
{ 0.037421, 0.013600, 0.038902 },
{ 0.042932, 0.016118, 0.046016 },
{ 0.048217, 0.018724, 0.053275 },
{ 0.053271, 0.021423, 0.060666 },
{ 0.058090, 0.024220, 0.068173 },
{ 0.062670, 0.027119, 0.075781 },
{ 0.067008, 0.030126, 0.083478 },
{ 0.071101, 0.033243, 0.091246 },
{ 0.074947, 0.036475, 0.099072 },
{ 0.078546, 0.039824, 0.106939 },
{ 0.081898, 0.043295, 0.114834 },
{ 0.085002, 0.046889, 0.122740 },
{ 0.087860, 0.050609, 0.130643 },
{ 0.090474, 0.054457, 0.138527 },
{ 0.092845, 0.058434, 0.146378 },
{ 0.094978, 0.062542, 0.154180 },
{ 0.096875, 0.066781, 0.161918 },
{ 0.098542, 0.071152, 0.169579 },
{ 0.099984, 0.075655, 0.177147 },
{ 0.101205, 0.080290, 0.184609 },
{ 0.102212, 0.085055, 0.191951 },
{ 0.103013, 0.089951, 0.199159 },
{ 0.103615, 0.094975, 0.206221 },
{ 0.104025, 0.100126, 0.213124 },
{ 0.104252, 0.105403, 0.219855 },
{ 0.104305, 0.110801, 0.226402 },
{ 0.104194, 0.116320, 0.232755 },
{ 0.103929, 0.121956, 0.238903 },
{ 0.103519, 0.127705, 0.244834 },
{ 0.102976, 0.133564, 0.250541 },
{ 0.102310, 0.139529, 0.256012 },
{ 0.101534, 0.145596, 0.261240 },
{ 0.100659, 0.151759, 0.266217 },
{ 0.099697, 0.158016, 0.270935 },
{ 0.098661, 0.164359, 0.275388 },
{ 0.097563, 0.170785, 0.279569 },
{ 0.096415, 0.177287, 0.283474 },
{ 0.095232, 0.183860, 0.287097 },
{ 0.094026, 0.190498, 0.290434 },
{ 0.092810, 0.197194, 0.293483 },
{ 0.091597, 0.203943, 0.296240 },
{ 0.090402, 0.210739, 0.298703 },
{ 0.089237, 0.217573, 0.300873 },
{ 0.088115, 0.224441, 0.302747 },
{ 0.087051, 0.231334, 0.304327 },
{ 0.086056, 0.238247, 0.305612 },
{ 0.085146, 0.245171, 0.306606 },
{ 0.084331, 0.252101, 0.307310 },
{ 0.083626, 0.259028, 0.307728 },
{ 0.083043, 0.265946, 0.307863 },
{ 0.082594, 0.272848, 0.307720 },
{ 0.082291, 0.279726, 0.307304 },
{ 0.082148, 0.286573, 0.306621 },
{ 0.082174, 0.293383, 0.305677 },
{ 0.082381, 0.300147, 0.304480 },
{ 0.082780, 0.306860, 0.303037 },
{ 0.083383, 0.313514, 0.301356 },
{ 0.084198, 0.320102, 0.299448 },
{ 0.085235, 0.326618, 0.297320 },
{ 0.086504, 0.333055, 0.294984 },
{ 0.088014, 0.339406, 0.292449 },
{ 0.089772, 0.345666, 0.289728 },
{ 0.091787, 0.351829, 0.286831 },
{ 0.094066, 0.357887, 0.283771 },
{ 0.096615, 0.363836, 0.280560 },
{ 0.099441, 0.369671, 0.277211 },
{ 0.102549, 0.375385, 0.273736 },
{ 0.105944, 0.380974, 0.270151 },
{ 0.109630, 0.386433, 0.266468 },
{ 0.113611, 0.391757, 0.262703 },
{ 0.117891, 0.396943, 0.258868 },
{ 0.122472, 0.401985, 0.254979 },
{ 0.127356, 0.406881, 0.251051 },
{ 0.132543, 0.411627, 0.247099 },
{ 0.138035, 0.416220, 0.243137 },
{ 0.143832, 0.420656, 0.239182 },
{ 0.149933, 0.424934, 0.235247 },
{ 0.156336, 0.429052, 0.231350 },
{ 0.163040, 0.433007, 0.227504 },
{ 0.170042, 0.436798, 0.223726 },
{ 0.177339, 0.440423, 0.220029 },
{ 0.184927, 0.443882, 0.216431 },
{ 0.192802, 0.447175, 0.212944 },
{ 0.200958, 0.450301, 0.209585 },
{ 0.209391, 0.453260, 0.206367 },
{ 0.218092, 0.456053, 0.203306 },
{ 0.227057, 0.458680, 0.200415 },
{ 0.236277, 0.461144, 0.197707 },
{ 0.245744, 0.463444, 0.195197 },
{ 0.255451, 0.465584, 0.192898 },
{ 0.265388, 0.467565, 0.190822 },
{ 0.275545, 0.469391, 0.188982 },
{ 0.285913, 0.471062, 0.187389 },
{ 0.296481, 0.472584, 0.186055 },
{ 0.307239, 0.473959, 0.184992 },
{ 0.318175, 0.475191, 0.184208 },
{ 0.329277, 0.476285, 0.183716 },
{ 0.340534, 0.477243, 0.183523 },
{ 0.351934, 0.478072, 0.183638 },
{ 0.363463, 0.478776, 0.184071 },
{ 0.375109, 0.479360, 0.184829 },
{ 0.386858, 0.479829, 0.185918 },
{ 0.398697, 0.480190, 0.187345 },
{ 0.410613, 0.480448, 0.189115 },
{ 0.422591, 0.480609, 0.191235 },
{ 0.434618, 0.480679, 0.193708 },
{ 0.446680, 0.480665, 0.196538 },
{ 0.458762, 0.480574, 0.199728 },
{ 0.470850, 0.480412, 0.203280 },
{ 0.482930, 0.480186, 0.207197 },
{ 0.494987, 0.479903, 0.211478 },
{ 0.507008, 0.479572, 0.216124 },
{ 0.518978, 0.479198, 0.221136 },
{ 0.530883, 0.478789, 0.226510 },
{ 0.542708, 0.478353, 0.232247 },
{ 0.554441, 0.477898, 0.238342 },
{ 0.566067, 0.477430, 0.244794 },
{ 0.577573, 0.476958, 0.251597 },
{ 0.588945, 0.476490, 0.258747 },
{ 0.600171, 0.476032, 0.266239 },
{ 0.611237, 0.475592, 0.274067 },
{ 0.622132, 0.475178, 0.282223 },
{ 0.632842, 0.474798, 0.290702 },
{ 0.643357, 0.474459, 0.299495 },
{ 0.653665, 0.474168, 0.308593 },
{ 0.663755, 0.473933, 0.317987 },
{ 0.673616, 0.473761, 0.327668 },
{ 0.683239, 0.473658, 0.337626 },
{ 0.692613, 0.473632, 0.347849 },
{ 0.701729, 0.473690, 0.358327 },
{ 0.710579, 0.473838, 0.369047 },
{ 0.719155, 0.474083, 0.379998 },
{ 0.727448, 0.474430, 0.391167 },
{ 0.735453, 0.474886, 0.402541 },
{ 0.743162, 0.475457, 0.414106 },
{ 0.750569, 0.476148, 0.425849 },
{ 0.757669, 0.476964, 0.437755 },
{ 0.764458, 0.477911, 0.449811 },
{ 0.770932, 0.478994, 0.462001 },
{ 0.777086, 0.480216, 0.474310 },
{ 0.782918, 0.481583, 0.486725 },
{ 0.788426, 0.483098, 0.499228 },
{ 0.793609, 0.484765, 0.511805 },
{ 0.798465, 0.486587, 0.524441 },
{ 0.802993, 0.488567, 0.537119 },
{ 0.807196, 0.490708, 0.549824 },
{ 0.811072, 0.493013, 0.562540 },
{ 0.814625, 0.495483, 0.575253 },
{ 0.817855, 0.498121, 0.587945 },
{ 0.820767, 0.500927, 0.600602 },
{ 0.823364, 0.503903, 0.613208 },
{ 0.825649, 0.507050, 0.625748 },
{ 0.827628, 0.510368, 0.638207 },
{ 0.829305, 0.513857, 0.650570 },
{ 0.830688, 0.517516, 0.662822 },
{ 0.831781, 0.521346, 0.674949 },
{ 0.832593, 0.525345, 0.686938 },
{ 0.833130, 0.529511, 0.698773 },
{ 0.833402, 0.533844, 0.710443 },
{ 0.833416, 0.538342, 0.721933 },
{ 0.833181, 0.543001, 0.733232 },
{ 0.832708, 0.547820, 0.744327 },
{ 0.832006, 0.552795, 0.755206 },
{ 0.831086, 0.557924, 0.765859 },
{ 0.829958, 0.563202, 0.776274 },
{ 0.828633, 0.568627, 0.786443 },
{ 0.827124, 0.574193, 0.796354 },
{ 0.825442, 0.579897, 0.805999 },
{ 0.823599, 0.585733, 0.815370 },
{ 0.821608, 0.591698, 0.824459 },
{ 0.819482, 0.597785, 0.833258 },
{ 0.817233, 0.603990, 0.841761 },
{ 0.814875, 0.610307, 0.849963 },
{ 0.812421, 0.616730, 0.857858 },
{ 0.809884, 0.623252, 0.865441 },
{ 0.807278, 0.629869, 0.872709 },
{ 0.804617, 0.636573, 0.879658 },
{ 0.801914, 0.643359, 0.886286 },
{ 0.799183, 0.650218, 0.892592 },
{ 0.796438, 0.657146, 0.898574 },
{ 0.793692, 0.664134, 0.904231 },
{ 0.790959, 0.671176, 0.909565 },
{ 0.788253, 0.678264, 0.914576 },
{ 0.785586, 0.685392, 0.919267 },
{ 0.782973, 0.692553, 0.923639 },
{ 0.780425, 0.699738, 0.927695 },
{ 0.777957, 0.706942, 0.931441 },
{ 0.775579, 0.714157, 0.934879 },
{ 0.773305, 0.721375, 0.938016 },
{ 0.771147, 0.728589, 0.940857 },
{ 0.769116, 0.735793, 0.943409 },
{ 0.767224, 0.742979, 0.945678 },
{ 0.765481, 0.750140, 0.947673 },
{ 0.763898, 0.757269, 0.949402 },
{ 0.762485, 0.764360, 0.950874 },
{ 0.761251, 0.771405, 0.952098 },
{ 0.760207, 0.778399, 0.953084 },
{ 0.759360, 0.785335, 0.953843 },
{ 0.758718, 0.792207, 0.954386 },
{ 0.758290, 0.799008, 0.954724 },
{ 0.758082, 0.805734, 0.954869 },
{ 0.758101, 0.812378, 0.954833 },
{ 0.758353, 0.818934, 0.954629 },
{ 0.758842, 0.825399, 0.954270 },
{ 0.759575, 0.831767, 0.953769 },
{ 0.760554, 0.838033, 0.953140 },
{ 0.761784, 0.844192, 0.952397 },
{ 0.763267, 0.850242, 0.951554 },
{ 0.765006, 0.856178, 0.950625 },
{ 0.767001, 0.861997, 0.949624 },
{ 0.769255, 0.867695, 0.948567 },
{ 0.771766, 0.873270, 0.947467 },
{ 0.774535, 0.878718, 0.946340 },
{ 0.777561, 0.884039, 0.945201 },
{ 0.780841, 0.889230, 0.944063 },
{ 0.784374, 0.894289, 0.942942 },
{ 0.788156, 0.899216, 0.941853 },
{ 0.792184, 0.904010, 0.940809 },
{ 0.796453, 0.908669, 0.939825 },
{ 0.800958, 0.913194, 0.938916 },
{ 0.805694, 0.917586, 0.938095 },
{ 0.810654, 0.921845, 0.937376 },
{ 0.815832, 0.925971, 0.936772 },
{ 0.821221, 0.929967, 0.936297 },
{ 0.826811, 0.933833, 0.935962 },
{ 0.832595, 0.937572, 0.935781 },
{ 0.838565, 0.941187, 0.935766 },
{ 0.844709, 0.944679, 0.935927 },
{ 0.851018, 0.948053, 0.936275 },
{ 0.857482, 0.951311, 0.936822 },
{ 0.864090, 0.954457, 0.937578 },
{ 0.870830, 0.957495, 0.938550 },
{ 0.877690, 0.960430, 0.939749 },
{ 0.884659, 0.963266, 0.941183 },
{ 0.891723, 0.966009, 0.942858 },
{ 0.898871, 0.968662, 0.944783 },
{ 0.906088, 0.971233, 0.946962 },
{ 0.913362, 0.973726, 0.949402 },
{ 0.920679, 0.976147, 0.952108 },
{ 0.928026, 0.978504, 0.955083 },
{ 0.935387, 0.980802, 0.958331 },
{ 0.942750, 0.983048, 0.961854 },
{ 0.950101, 0.985249, 0.965654 },
{ 0.957424, 0.987412, 0.969733 },
{ 0.964706, 0.989543, 0.974090 },
{ 0.971932, 0.991652, 0.978724 },
{ 0.979088, 0.993744, 0.983635 },
{ 0.986161, 0.995828, 0.988820 },
{ 0.993136, 0.997910, 0.994276 },
{ 1.000000, 1.000000, 1.000000 }
};

return internal::CalcLerp(x, data);
}

#if defined(TINYCOLORMAP_WITH_QT5) && defined(TINYCOLORMAP_WITH_EIGEN)
inline QImage CreateMatrixVisualization(const Eigen::MatrixXd& matrix)
{
Expand Down
25 changes: 13 additions & 12 deletions tools/png-exporter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ int main(int argc, char* argv[])

const std::vector<std::pair<tinycolormap::ColormapType, std::string>> colormap_types
{
{ tinycolormap::ColormapType::Parula, "Parula" },
{ tinycolormap::ColormapType::Heat, "Heat" },
{ tinycolormap::ColormapType::Jet, "Jet" },
{ tinycolormap::ColormapType::Turbo, "Turbo" },
{ tinycolormap::ColormapType::Hot, "Hot" },
{ tinycolormap::ColormapType::Gray, "Gray" },
{ tinycolormap::ColormapType::Magma, "Magma" },
{ tinycolormap::ColormapType::Inferno, "Inferno" },
{ tinycolormap::ColormapType::Plasma, "Plasma" },
{ tinycolormap::ColormapType::Viridis, "Viridis" },
{ tinycolormap::ColormapType::Cividis, "Cividis" },
{ tinycolormap::ColormapType::Github, "Github" },
{ tinycolormap::ColormapType::Parula, "Parula" },
{ tinycolormap::ColormapType::Heat, "Heat" },
{ tinycolormap::ColormapType::Jet, "Jet" },
{ tinycolormap::ColormapType::Turbo, "Turbo" },
{ tinycolormap::ColormapType::Hot, "Hot" },
{ tinycolormap::ColormapType::Gray, "Gray" },
{ tinycolormap::ColormapType::Magma, "Magma" },
{ tinycolormap::ColormapType::Inferno, "Inferno" },
{ tinycolormap::ColormapType::Plasma, "Plasma" },
{ tinycolormap::ColormapType::Viridis, "Viridis" },
{ tinycolormap::ColormapType::Cividis, "Cividis" },
{ tinycolormap::ColormapType::Github, "Github" },
{ tinycolormap::ColormapType::Cubehelix, "Cubehelix" },
};

for (const auto& colormap_type : colormap_types)
Expand Down

0 comments on commit 8d58a26

Please sign in to comment.