Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yuki-koyama/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
https://github.com/yuki-koyama/color-util
ciede2000 cielab ciexyz rgb
Last synced: about 2 months ago
JSON representation
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
- Host: GitHub
- URL: https://github.com/yuki-koyama/color-util
- Owner: yuki-koyama
- License: mit
- Created: 2018-04-26T12:22:13.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-11-24T06:17:01.000Z (8 months ago)
- Last Synced: 2024-02-07T10:54:00.417Z (5 months ago)
- Topics: ciede2000, cielab, ciexyz, rgb
- Language: C++
- Homepage:
- Size: 47.9 KB
- Stars: 92
- Watchers: 5
- Forks: 5
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-hpp - color-util - koyama/color-util?style=social)](https://github.com/yuki-koyama/color-util/stargazers/) | Colors, Color space converters for RGB, HSL, XYZ, Lab, etc. | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | (Image Processing)
README
# color-util
![macOS](https://github.com/yuki-koyama/color-util/workflows/macOS/badge.svg)
![Ubuntu](https://github.com/yuki-koyama/color-util/workflows/Ubuntu/badge.svg)A header-only C++11 library for handling colors, including color space converters between RGB, XYZ, Lab, etc. and color difference calculators such as CIEDE2000.
## Color Space Convertors
- Conversion between RGB and HSL
- `color-util/RGB_to_HSL.hpp`
- `color-util/HSL_to_RGB.hpp`
- Conversion between sRGB and CIEXYZ (D65)
- `color-util/RGB_to_XYZ.hpp`
- `color-util/XYZ_to_RGB.hpp`
- Conversion between CIEXYZ (D65) and CIELAB (a.k.a. CIE L\*a\*b\*) (D65)
- `color-util/XYZ_to_Lab.hpp`
- `color-util/Lab_to_XYZ.hpp`## Color Difference Calculators
### CIE76
Given two CIELAB colors, `calculate_CIE76` calculates a *perceptual* difference between these two colors based on a metric called CIE76. This function is defined in `color-util/CIE76.hpp`.
It is known that this metric is not perceptually uniform especially with saturated colors. In general, CIEDE2000 is considered as a better choice.
### CIEDE2000
Given two CIELAB colors, `calculate_CIEDE2000` calculates a *perceptual* difference between these two colors based on a metric called CIEDE2000. This function is defined in `color-util/CIEDE2000.hpp`.
The correctness of the implementation is verified through the test dataset provided by Gaurav Sharma .
## Dependency
- Eigen
## Installation
color-util is a *header-only* library, so it can be used by just copying the directory named `color-util` to the `include` directory of the target project. No need to build it in advance.
For CMake users, this repository includes `CMakeLists.txt`; it can be installed by
```bash
cmake [PATH_TO_THIS_REPOSITORY] -DCMAKE_INSTALL_PREFIX=[PATH_TO_INSTALL_DIRECTORY]
make install
```
Alternatively, if the target project is also managed by CMake, the `ExternalProject_Add` command is also useful.## Example
Here is an example code for calculating a perceptual distance of two sRGB colors. First, include necessary headers:
```cpp
#include
#include
#include
```
Define the target colors in sRGB:
```cpp
colorutil::RGB rgb_color_1(200.0 / 255.0, 100.0 / 255.0, 20.0 / 200.0);
colorutil::RGB rgb_color_2(100.0 / 255.0, 200.0 / 255.0, 50.0 / 200.0);
```
CIEDE2000 requires CIELAB colors as input, so convert them to CIELAB via CIEXYZ:
```cpp
colorutil::XYZ xyz_color_1 = colorutil::convert_RGB_to_XYZ(rgb_color_1);
colorutil::XYZ xyz_color_2 = colorutil::convert_RGB_to_XYZ(rgb_color_2);
colorutil::Lab lab_color_1 = colorutil::convert_XYZ_to_Lab(xyz_color_1);
colorutil::Lab lab_color_2 = colorutil::convert_XYZ_to_Lab(xyz_color_2);
```
Finally, calculate the perceptual distance of the two colors:
```cpp
double difference = colorutil::calculate_CIEDE2000(lab_color_1, lab_color_2);
```
In this case, it returns `53.8646` as the perceptual distance between the two colors.## License
MIT License.
## Contribute
Pull requests are welcome.