All Projects β†’ JuliaGraphics β†’ ColorVectorSpace.jl

JuliaGraphics / ColorVectorSpace.jl

Licence: other
Treat colors as if they are n-vectors for the purposes of arithmetic

Programming Languages

julia
2034 projects

Projects that are alternatives of or similar to ColorVectorSpace.jl

server-media
This repository collects icons, logos & information about game servers.
Stars: ✭ 29 (+3.57%)
Mutual labels:  images
instagram-get-images
Instagram get images πŸŒ„ (hashtags, account, locations) with puppeteer
Stars: ✭ 69 (+146.43%)
Mutual labels:  images
DICOM.jl
Julia package for reading and writing DICOM (Digital Imaging and Communications in Medicine) files
Stars: ✭ 45 (+60.71%)
Mutual labels:  images
lifelights
Video games blended with home automation. Control your IoT devices based on in-game statuses!
Stars: ✭ 80 (+185.71%)
Mutual labels:  rgb
Wortuhr
Software fΓΌr eine ESP8266 basierte Wortuhr mit verschiedenen Layouts
Stars: ✭ 30 (+7.14%)
Mutual labels:  rgb
Rotary Encoder Breakout-Illuminated
This is a clever little breakout board for both the RGB and R/G illuminated rotary encoders.
Stars: ✭ 16 (-42.86%)
Mutual labels:  rgb
EmotionDetection
An emotion extraction system for images, that extracts emotion which will be felt by the user of viewing the image, representing them in a 2-Dimensional space that represents Arousal and Valence.
Stars: ✭ 26 (-7.14%)
Mutual labels:  images
osbuild
Build-Pipelines for Operating System Artifacts
Stars: ✭ 95 (+239.29%)
Mutual labels:  images
react-crossfade-image
react-crossfade-image - Simple React component for crossfading images - No CSS needed
Stars: ✭ 33 (+17.86%)
Mutual labels:  images
ColorTranslator
A JavaScript library, written in TypeScript, to convert among different color models
Stars: ✭ 34 (+21.43%)
Mutual labels:  rgb
gopher-logos
adorable gopher logos
Stars: ✭ 106 (+278.57%)
Mutual labels:  images
hydra-antlia
A collection of functions for Hydra
Stars: ✭ 45 (+60.71%)
Mutual labels:  rgb
eruption
Realtime RGB LED Driver for Linux
Stars: ✭ 140 (+400%)
Mutual labels:  rgb
rgb-core
RGB Core Library: consensus validation for private & scalable client-validated smart contracts on Bitcoin & Lightning
Stars: ✭ 99 (+253.57%)
Mutual labels:  rgb
go-rainbow
Golang Helper for beautiful CLI Applications
Stars: ✭ 86 (+207.14%)
Mutual labels:  rgb
Sand-Table
An open-source platform for building DIY sand tables (like the Sisyphus or ZenXY)
Stars: ✭ 99 (+253.57%)
Mutual labels:  rgb
GBVS360-BMS360-ProSal
Extending existing saliency prediction models from 2D to omnidirectional images
Stars: ✭ 25 (-10.71%)
Mutual labels:  images
use-images-loaded
πŸ–ΌοΈ Returns true once all the images inside a container are loaded
Stars: ✭ 82 (+192.86%)
Mutual labels:  images
av.imageview
Titanium native ImageView module that extends the default Titanium ImageView with more capabilities and a different caching system.
Stars: ✭ 97 (+246.43%)
Mutual labels:  images
vdcd
vdcd - virtual device controller daemon/framework for digitalSTROM
Stars: ✭ 19 (-32.14%)
Mutual labels:  rgb

ColorVectorSpace

Build Status codecov.io

This package is an add-on to ColorTypes, and provides fast mathematical operations for objects with types such as RGB and Gray. Specifically, with this package both grayscale and RGB colors are treated as if they are points in a normed vector space.

Introduction

Colorspaces such as RGB, unlike XYZ, are technically non-linear; perhaps the most "colorimetrically correct" approach when averaging two RGBs is to first convert each to XYZ, average them, and then convert back to RGB. Nor is there a clear definition of computing the sum of two colors. As a consequence, Julia's base color package, ColorTypes, does not support mathematical operations on colors.

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. The role of this package is to extend ColorTypes to support such mathematical operations. Specifically, it defines + and multiplication by a scalar (and by extension, - and division by a scalar) for grayscale and AbstractRGB colors. These are the requirements of a vector space.

If you're curious about how much the "colorimetrically correct" and "vector space" views differ, 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.

ColorVectorSpace

This package also defines norm(c) for RGB and grayscale colors. This makes these color spaces normed vector spaces. Note that norm has been designed to satisfy equivalence of grayscale and RGB representations: if x is a scalar, then norm(x) == norm(Gray(x)) == norm(RGB(x, x, x)). Effectively, there's a division-by-3 in the norm(::RGB) case compared to the Euclidean interpretation of the RGB vector space. Equivalence is an important principle for the Colors ecosystem, and violations should be reported as likely bugs. One violation is abs2; see the section below for more detail.

Usage

using ColorTypes, ColorVectorSpace

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

However, there are some additional operations that you may need to distinguish carefully.

Multiplication

Grayscale values are conceptually similar to scalars, and consequently it seems straightforward to define multiplication of two grayscale values. RGB values present more options. This package supports three different notions of multiplication: the inner product, the hadamard (elementwise) product, and the tensor product.

julia> c1, c2 = RGB(0.2, 0.3, 0.4), RGB(0.5, 0.3, 0.2)
(RGB{Float64}(0.2,0.3,0.4), RGB{Float64}(0.5,0.3,0.2))

julia> c1β‹…c2     # \cdot<TAB> # or dot(c1, c2)
0.09000000000000001

# This is equivelant to `mapc(*, c1, c2)`
julia> c1βŠ™c2     # \odot<TAB> # or hadamard(c1, c2)
RGB{Float64}(0.1,0.09,0.08000000000000002)

julia> c1βŠ—c2    # \otimes<TAB> # or tensor(c1, c2)
RGBRGB{Float64}:
 0.1   0.06  0.04
 0.15  0.09  0.06
 0.2   0.12  0.08

Note that c1β‹…c2 = (c1.r*c2.r + c1.g*c2.g + c1.b*c2.b)/3, where the division by 3 ensures the equivalence norm(x) == norm(Gray(x)) == norm(RGB(x, x, x)).

Ordinary multiplication * is not supported because it is not obvious which one of these should be the default option.

However, * is defined for grayscale since all these three multiplication operations (i.e., β‹…, βŠ™ and βŠ—) are equivalent in the 1D vector space.

Variance

The variance v = E((c - ΞΌ)^2) (or its bias-corrected version) involves a multiplication, and to be consistent with the above you must specify which sense of multiplication you wish to use:

julia> cs = [c1, c2]
2-element Array{RGB{Float64},1} with eltype RGB{Float64}:
 RGB{Float64}(0.2,0.3,0.4)
 RGB{Float64}(0.5,0.3,0.2)

julia> varmult(β‹…, cs)
0.021666666666666667

julia> varmult(βŠ™, cs)
RGB{Float64}(0.045,0.0,0.020000000000000004)

julia> varmult(βŠ—, cs)
RGBRGB{Float64}:
  0.045  0.0  -0.03
  0.0    0.0   0.0
 -0.03   0.0   0.02

The corresponding stdmult computes standard deviation.

abs and abs2

To begin with, there is no general and straightforward definition of the absolute value of a vector. There are two reasonably intuitive definitions of abs/abs2: as a channel-wise operator or as a function which returns a real number based on the norm. For the latter, there are also variations in the definition of norm.

In ColorVectorSpace v0.9 and later, abs is defined as a channel-wise operator. abs2 returns a real-valued scalar. In previous versions of ColorVectorSpace, for g = Gray(0.3), ColorVectorSpace returned different values for abs2(g) and abs2(RGB(g)). This breaks the equivalence of g and RGB(g). This behavior is retained, with a deprecation warning, starting with ColorVectorSpace 0.9.6.

In the future, abs2 will be defined as abs2(c) == cβ‹…c β‰ˆ norm(c)^2. This effectively divides the old result by 3; code that imposes thresholds on abs2(c) may need to be updated. You can obtain that behavior now--and circumvent the deprecation warning-- by using ColorVectorSpace.Future.abs2(c).

We anticipate the following transition schedule:

  • Sept 21, 2021: release ColorVectorSpace 0.9.7 with both abs2 and Future.abs2. abs2 will have a "quiet" deprecation warning (visible with --depwarn=yes or when running Pkg.test)
  • May 19, 2022: make the deprecation warning "noisy" (cannot be turned off). This is designed to catch user-level scripts that may need to update thresholds or other constants.
  • *July 1, 2022: transition abs2 to the new definition and make Future.abs2 give a "noisy" depwarn to revert to regular abs2.
  • *Dec 1, 2022: remove Future.abs2.

The two marked with * denote breaking releases.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].