Treat colors as if they are n-vectors for the purposes of arithmetic
12 Stars
Updated Last
1 Year Ago
Started In
August 2015


Build Status

This package is an add-on to ColorTypes, and provides fast mathematical operations for objects with types such as RGB and Gray.


Colorspaces such as RGB, unlike XYZ, are technically non-linear; the "colorimetrically correct" approach when averaging two RGBs is to first convert each to XYZ, average them, and then convert back to RGB.

However, particularly in image processing it is common to ignore this concern, and for the sake of performance treat an RGB as if it were a 3-vector. This package provides such operations.

If you're curious about how much difference it makes, the following diagram might help. The first 10 distinguishable_colors were generated, and all pairs were averaged. Each box represents the average of the pair of diagonal elements intersected by tracing vertically and horizontally; within each box, the upper diagonal is the "colorimetrically-correct" version, while the lower diagonal represents the "RGB vector space" version.



using ColorTypes, ColorVectorSpace

That's it. Just by loading ColorVectorSpace, most basic mathematical operations will "just work" on AbstractRGB, AbstractGray (OpaqueColor{T,1}), TransparentRGB, and TransparentGray objects. (See definitions for the latter inside of ColorTypes).

If you discover missing operations, please open an issue, or better yet submit a pull request.