{"id":13731660,"url":"https://github.com/yuki-koyama/tinycolormap","last_synced_at":"2025-04-05T12:07:36.987Z","repository":{"id":37550357,"uuid":"128155286","full_name":"yuki-koyama/tinycolormap","owner":"yuki-koyama","description":"A header-only, single-file library for colormaps written in C++11","archived":false,"fork":false,"pushed_at":"2024-08-21T16:38:29.000Z","size":170,"stargazers_count":324,"open_issues_count":3,"forks_count":42,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-13T01:27:40.357Z","etag":null,"topics":["color","colormap","header-only","map","viridis","visualization"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuki-koyama.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-05T03:38:00.000Z","updated_at":"2024-10-11T10:48:39.000Z","dependencies_parsed_at":"2024-01-31T02:09:36.685Z","dependency_job_id":"280dd0a0-edba-49d2-9133-4afcf7cb3375","html_url":"https://github.com/yuki-koyama/tinycolormap","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuki-koyama%2Ftinycolormap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuki-koyama%2Ftinycolormap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuki-koyama%2Ftinycolormap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuki-koyama%2Ftinycolormap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuki-koyama","download_url":"https://codeload.github.com/yuki-koyama/tinycolormap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332609,"owners_count":20921853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color","colormap","header-only","map","viridis","visualization"],"created_at":"2024-08-03T02:01:35.078Z","updated_at":"2025-04-05T12:07:36.967Z","avatar_url":"https://github.com/yuki-koyama.png","language":"C++","funding_links":[],"categories":["Graphics"],"sub_categories":[],"readme":"# tinycolormap\n\n![macOS](https://github.com/yuki-koyama/tinycolormap/workflows/macOS/badge.svg)\n![Ubuntu](https://github.com/yuki-koyama/tinycolormap/workflows/Ubuntu/badge.svg)\n![GitHub](https://img.shields.io/github/license/yuki-koyama/tinycolormap)\n\nA header-only, single-file library for colormaps written in C++11.\n\n## Available Colormaps\n\n### Matlab\n\n| Name     | Sample                         |\n|:--------:|:------------------------------:|\n| Parula   | ![](docs/samples/Parula.png)   |\n| Heat     | ![](docs/samples/Heat.png)     |\n| Hot      | ![](docs/samples/Hot.png)      |\n| Jet      | ![](docs/samples/Jet.png)      |\n| Gray     | ![](docs/samples/Gray.png)     |\n| HSV      | ![](docs/samples/HSV.png)     |\n\nReference: \u003chttps://www.mathworks.com/help/matlab/ref/colormap.html\u003e\n\nThe 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.\n\n### Matplotlib\n\n| Name     | Sample                         |\n|:--------:|:------------------------------:|\n| Magma    | ![](docs/samples/Magma.png)    |\n| Inferno  | ![](docs/samples/Inferno.png)  |\n| Plasma   | ![](docs/samples/Plasma.png)   |\n| Viridis  | ![](docs/samples/Viridis.png)  |\n| Cividis  | ![](docs/samples/Cividis.png)  |\n\nThese 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.\n\nMagma, Inferno, Plasma, Viridis are released under CC0 by Nathaniel J. Smith, Stefan van der Walt, and (in the case of Viridis) Eric Firing: \u003chttps://github.com/BIDS/colormap/blob/master/colormaps.py\u003e. Their python code is adapted for the use in C++11.\n\nCividis is released under CC0 by the authors of PLOS ONE paper (Jamie R. Nuñez, Christopher R. Anderton, Ryan S. Renslow): \u003chttps://doi.org/10.1371/journal.pone.0199239\u003e. We incorporated the LUT into C++11.\n\n### GitHub\n\n| Name     | Sample                         |\n|:--------:|:------------------------------:|\n| Github   | ![](docs/samples/Github.png)   |\n\nThis colormap is designed to mimic the color scheme used in GitHub contributions visualization.\n\n### Other\n\n| Name     | Sample                         |\n|:--------:|:------------------------------:|\n| Turbo    | ![](docs/samples/Turbo.png)    |\n\nTurbo 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.\n\n| Name      | Sample                          |\n|:---------:|:-------------------------------:|\n| Cubehelix | ![](docs/samples/Cubehelix.png) |\n\nCubehelix 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](https://ui.adsabs.harvard.edu/abs/2011BASI...39..289G/abstract) for details.\n\n## Dependency\n\ntinycolormap does not have any dependencies except for C++11 standard library.\n\n## Installation\n\ntinycolormap is a header-only library, so you do not need to compile it. You can use it by\n\n- Adding the path to the `include` directory in the cloned tinycolormap repository to your project's include paths, or\n- Copying the file `tinycolormap.hpp` to your project (note that tinycolormap consists of only that single file).\n\nIf your project is managed by Cmake \u003chttps://cmake.org/\u003e, `add_subdirectory` or `ExternalProject_Add` commands are useful as tinycolormap provides `CMakeLists.txt` for this purpose.\n\n## Usage\n\nThe core function of this library is\n```cpp\ninline Color GetColor(double x, ColormapType type);\n```\nwhere `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`.\n\nHere is a working code:\n```cpp\n#include \u003ciostream\u003e\n#include \u003ctinycolormap.hpp\u003e\n\nint main()\n{\n  // Define a target value. This value should be in [0, 1]; otherwise, it will be cropped to 0 or 1.\n  const double value = 0.5;\n\n  // Get the mapped color. Here, Viridis is specified as the colormap.\n  const tinycolormap::Color color = tinycolormap::GetColor(value, tinycolormap::ColormapType::Viridis);\n\n  // Print the RGB values. Each value is in [0, 1].\n  std::cout \u003c\u003c \"r = \" \u003c\u003c color.r() \u003c\u003c \", g = \" \u003c\u003c color.g() \u003c\u003c \", b = \" \u003c\u003c color.b() \u003c\u003c std::endl;\n\n  return 0;\n}\n```\n\n### Quantized colors\n\ntinycolormap 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:\n\n| Name     | Sample                                  |\n|:--------:|:---------------------------------------:|\n| Parula   | ![](docs/samples/Parula_10levels.png)   |\n\nNote that the supported range for number of levels is `[1, 255]`.\n\nHere is an example code that uses colormap quantization:\n```cpp\nint main()\n{\n  // Define a target value. This value should be in [0, 1]; otherwise, it will be cropped to 0 or 1.\n  const double value = 0.5;\n\n  // Define number of levels for the colormap quantization. This value should be in [1, 255]; otherwise, it will be cropped to 1 or 255.\n  const unsigned int num_levels = 10;\n\n  // Get the mapped color. Here, Parula is specified as the colormap.\n  const tinycolormap::Color color = tinycolormap::GetQuantizedColor(value, num_levels, tinycolormap::ColormapType::Parula);\n\n  // Print the RGB values. Each value is in [0, 1].\n  std::cout \u003c\u003c \"r = \" \u003c\u003c color.r() \u003c\u003c \", g = \" \u003c\u003c color.g() \u003c\u003c \", b = \" \u003c\u003c color.b() \u003c\u003c std::endl;\n\n  return 0;\n}\n```\n\n## Options for External Libraries Integration\n\n### Qt5 Support\n\nWhen `TINYCOLORMAP_WITH_QT5` is defined before including `tinycolormap.hpp`, for example,\n```cpp\n#define TINYCOLORMAP_WITH_QT5\n#include \u003ctinycolormap.hpp\u003e\n```\n(or `TINYCOLORMAP_WITH_QT5` CMake option is `ON`), this library offers an additional utility function:\n```cpp\nconst QColor color = tinycolormap::GetColor(x).ConvertToQColor();\n```\n\n### Eigen Support\n\nWhen `TINYCOLORMAP_WITH_EIGEN` is defined before including `tinycolormap.hpp`, for example,\n```cpp\n#define TINYCOLORMAP_WITH_EIGEN\n#include \u003ctinycolormap.hpp\u003e\n```\n(or `TINYCOLORMAP_WITH_EIGEN` CMake option is `ON`), this library offers an additional utility function:\n```cpp\nconst Eigen::Vector3d color = tinycolormap::GetColor(x).ConvertToEigen();\n```\n\n###  Qt5 and Eigen Support\n\nWhen both Qt5 and Eigen are available, this library offers additional utility functions:\n```cpp\ninline QImage CreateMatrixVisualization(const Eigen::MatrixXd\u0026 matrix);\ninline void ExportMatrixVisualization(const Eigen::MatrixXd\u0026 matrix, const std::string\u0026 path);\n```\n\n### GLM Support\n\nWhen `TINYCOLORMAP_WITH_GLM` is defined before including `tinycolormap.hpp`, for example,\n```cpp\n#define TINYCOLORMAP_WITH_GLM\n#include \u003ctinycolormap.hpp\u003e\n```\n(or `TINYCOLORMAP_WITH_GLM` CMake option is `ON`), this library offers an additional utility function:\n```cpp\nconst glm::vec3 color = tinycolormap::GetColor(x).ConvertToGLM();\n```\n\n## Tools (Optional)\n\nThis repository includes the following optional tools:\n\n- PNG Exporter: This tool exports all the available colormaps as PNG images.\n\n### Tools Build Instruction\n\nThe optional tools are managed by CMake \u003chttps://cmake.org/\u003e. They can be built by, for example,\n```bash\nmkdir build\ncd build\ncmake [PATH_TO_TINYCOLORMAP] -DTINYCOLORMAP_BUILD_TOOLS=ON\nmake\n```\n\n## Projects using tinycolormap\n\n- riCOM \u003chttps://github.com/ThFriedrich/riCOM_cpp\u003e\n- OpenSiv3D \u003chttps://github.com/Siv3D/OpenSiv3D\u003e\n- SLiM \u003chttps://github.com/MesserLab/SLiM\u003e\n- Neper: Polycrystal Generation and Meshing \u003chttp://neper.info/\u003e\n- Unblending (Pacific Graphics 2018) \u003chttps://github.com/yuki-koyama/unblending\u003e\n- OptiMo (CHI 2018) \u003chttps://github.com/yuki-koyama/optimo\u003e\n- Sequential Line Search (SIGGRAPH 2017) \u003chttps://github.com/yuki-koyama/sequential-line-search\u003e\n- SelPh (CHI 2016) \u003chttps://github.com/yuki-koyama/selph\u003e\n- VisOpt Slider (UIST 2014) \u003chttps://github.com/yuki-koyama/visoptslider\u003e\n\n## License\n\nThe MIT License (except for `tools/png-exporter/stb_image_write.h`, which is released under public domain).\n\n## Contribute\n\nPull requests are welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuki-koyama%2Ftinycolormap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuki-koyama%2Ftinycolormap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuki-koyama%2Ftinycolormap/lists"}