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

Overview

color-util

macOS Ubuntu

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 http://www2.ece.rochester.edu/~gsharma/ciede2000/.

Dependency

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 https://cmake.org/ users, this repository includes CMakeLists.txt; it can be installed by

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:

#include <color-util/RGB_to_XYZ.hpp>
#include <color-util/XYZ_to_Lab.hpp>
#include <color-util/CIEDE2000.hpp>

Define the target colors in sRGB:

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:

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:

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.

You might also like...
C++ image processing and machine learning library with using of SIMD: SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, AVX-512, VMX(Altivec) and VSX(Power7), NEON for ARM.

Introduction The Simd Library is a free open source image processing and machine learning library, designed for C and C++ programmers. It provides man

libspng is a C library for reading and writing PNG format files with a focus on security and ease of use.
libspng is a C library for reading and writing PNG format files with a focus on security and ease of use.

libspng (simple png) is a C library for reading and writing Portable Network Graphics (PNG) format files with a focus on security and ease of use.

Tiny ISO-compliant C++ EXIF and XMP parsing library for JPEG.

TinyEXIF: Tiny ISO-compliant C++ EXIF and XMP parsing library for JPEG Introduction TinyEXIF is a tiny, lightweight C++ library for parsing the metada

Video++, a C++14 high performance video and image processing library.

Video++ Video++ is a video and image processing library taking advantage of the C++14 standard to ease the writing of fast video and image processing

ZT is a zig-contained library that automatically compiles+links ImGui, OpenGL, and GLFW into typed packages.
ZT is a zig-contained library that automatically compiles+links ImGui, OpenGL, and GLFW into typed packages.

ZT is a zig-contained library that automatically compiles+links ImGui, OpenGL, and GLFW into typed packages. By zig contained I mean that ZT is intend

ppl.cv is a high-performance image processing library of openPPL supporting x86 and cuda platforms.

ppl.cv is a high-performance image processing library of openPPL supporting x86 and cuda platforms.

The CImg Library is a small and open-source C++ toolkit for image processing
The CImg Library is a small and open-source C++ toolkit for image processing

http://cimg.eu The CImg Library is a small and open-source C++ toolkit for image processing, designed with these properties in mind: CImg defines clas

Pangolin: a lightweight portable rapid development library for managing OpenGL display / interaction and abstracting video input.

What is Pangolin Pangolin is a lightweight portable rapid development library for managing OpenGL display / interaction and abstracting video input. A

Video, Image and GIF upscale/enlarge(Super-Resolution) and Video frame interpolation. Achieved with Waifu2x, SRMD, RealSR,  Anime4K, RIFE, CAIN, DAIN and ACNet.
Video, Image and GIF upscale/enlarge(Super-Resolution) and Video frame interpolation. Achieved with Waifu2x, SRMD, RealSR, Anime4K, RIFE, CAIN, DAIN and ACNet.

Video, Image and GIF upscale/enlarge(Super-Resolution) and Video frame interpolation. Achieved with Waifu2x, SRMD, RealSR, Anime4K, RIFE, CAIN, DAIN and ACNet.

Comments
Releases(v0.5.0)
  • v0.5.0(Sep 6, 2020)

  • v0.4.0(Jan 28, 2020)

    • Setup GitHub Actions for automatic testing
    • Add a clang-format config file and apply it to the sources
    • Use constexpr when possible, which improves performance
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Sep 13, 2018)

    This release contains the following features.

    • Interface library definition in cmake, which makes it easier to use this library in other cmake projects
    • CIE76 color difference
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(May 11, 2018)

  • v0.1.0(Apr 30, 2018)

Owner
Yuki Koyama
Researcher
Yuki Koyama
Small header-only C library to decompress any BC compressed image

Small header-only C library to decompress any BC compressed image

null 92 Jan 1, 2023
image color filters

ifilter ======= Basic image color filters. ifilter reads an image from standard input, applies a color filter and dumps the resulting image to standa

phil9 9 Dec 16, 2022
Utility to combine color channels from different textures into a single output.

unity-texture-packer ?? Utility to merge different texture channels into a final texture output. Install Using Git Make sure the Git client is install

Andy Duboc 587 Dec 28, 2022
A slim, fast and header-only GIF loader written in C

gif_load This is an ANSI C compatible animated GIF loader in a single header file of less than 300 lines of code (less than 200 without empty lines an

Andrey Guskov 68 Dec 10, 2022
NanoPM, single header only PatchMatch

NanoPM, single header only PatchMatch NanoPM is a single header-only implementation of PatchMatch algorithm written in C++. Could be used for variety

null 67 Sep 27, 2022
ImGuiFileDialog is a file selection dialog built for (and using only) Dear ImGui

ImGuiFileDialog Purpose ImGuiFileDialog is a file selection dialog built for (and using only) Dear ImGui. My primary goal was to have a custom pane wi

Aiekick 790 Jan 4, 2023
NanoSVG is a simple stupid single-header-file SVG parse

This project is not actively maintained. Nano SVG Parser NanoSVG is a simple stupid single-header-file SVG parse.

Mikko Mononen 1.4k Dec 31, 2022
This library provides a cross-platform image loading library in C11 for projects based on our foundation library

Image Library - Public Domain This library provides a cross-platform image loading library in C11 for projects based on our foundation library.

Mattias Jansson 1 Jan 29, 2022
PillowResize library is a C++ porting of the resize method from the Pillow python library.

Pillow Resize Table of Contents Description Compilation Installation Usage Description PillowResize library is a C++ porting of the resize method from

Zuru Tech 47 Nov 17, 2022