Index

ColorSchemeTools._RGBA_to_UInt32Method
_RGBA_to_UInt32(rgb)

Convert an array of RGB values to an array of UInt32 values for use as a colormap.

Usage:

uint32rgb = _RGBA_to_UInt32(rgbmap)

Argument:

rgbmap - Vector of ColorTypes.RGBA values

Returns:

uint32rgb, an array of UInt32 values packed with the 8 bit RGB values.
source
ColorSchemeTools._cie76Method
_cie76(L::Array, a::Array, b::Array, W::Array)

Compute weighted Delta E between successive entries in a colormap using the CIE76 formula + weighting

Usage:

deltaE = _cie76(L::Array, a::Array, b::Array, W::Array)
source
ColorSchemeTools._ciede2000Method
_ciede2000(L::Array, a::Array, b::Array, W::Array)

Compute weighted Delta E between successive entries in a colormap using the CIEDE2000 formula + weighting

Usage:

deltaE = _ciede2000(L::Array, a::Array, b::Array, W::Array)
source
ColorSchemeTools._gaussfilt1dMethod
_gaussfilt1d(s::Array, sigma::Real)

Apply a 1D Gaussian filter to s. Filtering at the ends is done using zero padding.

Usage:

sm = _gaussfilt1d(s::Array, sigma::Real)
source
ColorSchemeTools._interp1Method
_interp1(x, y, xi)

Simple 1D linear interpolation of an array of data

Usage:

yi = _interp1(x, y, xi)

Arguments:

x - Array of coordinates at which y is defined

y - Array of values at coordinates x

xi - Coordinate locations at which you wish to interpolate y values

Returns:

yi - Values linearly interpolated from y at xi

Interpolates y, defined at values x, at locations xi and returns the corresponding values as yi.

x is assumed increasing but not necessarily equi-spaced. xi values do not need to be sorted.

If any xi are outside the range of x, then the corresponding value of yi is set to the appropriate end value of y.

source
ColorSchemeTools._lab_to_srgbMethod
_lab_to_srgb(lab::AbstractMatrix{T}) where {T}

Convert an Nx3 array of CIELAB values in a colormap to an Nx3 array of RGB values. Function can also be used to convert a 3 channel CIELAB image to a 3 channel RGB image Note it appears that the Colors.convert() function uses a default white point of D65

Usage:

rgb = _lab_to_srgb(lab)

Argument:

lab - N x 3 array of CIELAB values of a 3 channel CIELAB image

Returns:

rgb - N x 3 array of RGB values or a 3 channel RGB image

See also: srgbto_lab

source
ColorSchemeTools._linearrgbmapFunction
_linearrgbmap(C::Array, N::Int=256)

Linear RGB colourmap from black to a specified color.

Usage:

cmap = _linearrgbmap(C, N)

Arguments:

C - 3-vector specifying RGB colour

N - Number of colourmap elements, defaults to 256

Returns

cmap - an N element ColorTypes.RGBA colourmap ranging from [0 0 0] to RGB colour C.

You should pass the result through equalize() to obtain uniform steps in perceptual lightness.

source
ColorSchemeTools._smoothMethod
_smooth(L::Array{T,1}, sigma::Real, cyclic::Bool) where {T<:Real}

Smooth an array of values but also ensure end values are not altered or, if the map is cyclic, ensures smoothing is applied across the end points in a cyclic manner.

Assume input data is a column vector.

source
ColorSchemeTools._srgb_to_labMethod
_srgb_to_lab(rgb::AbstractMatrix{T}) where {T}

Convert an Nx3 array of RGB values in a colormap to an Nx3 array of CIELAB values. Function can also be used to convert a 3 channel RGB image to a 3 channel CIELAB image Note it appears that the Colors.convert() function uses a default white point of D65

Usage:

lab = _srgb_to_lab(rgb)

Argument:

rgb - A N x 3 array of RGB values or a 3 channel RGB image.

Returns:

 lab - A N x 3 array of Lab values of a 3 channel CIELAB image.

See also: labto_srgb

source
ColorSchemeTools.add_alphaFunction
add_alpha(cs::ColorScheme, alpha::Real=0.5)

Make a copy of the colorscheme cs with alpha opacity value alpha.

Example

Make a copy of the PuOr colorscheme and set every element of it to have alpha opacity 0.5

add_alpha(ColorSchemes.PuOr, 0.5)
source
ColorSchemeTools.add_alphaMethod
add_alpha(cs::ColorScheme, r::Range)

Make a copy of the colorscheme cs with alpha opacity values in the range r.

Example

Make a copy of the PuOr colorscheme, set the first element to have alpha opacity 0.5, the last element to have opacity 0.0, with intermediate elements taking values between 0.5 and 1.0.

add_alpha(ColorSchemes.PuOr, 0.5:0.1:1.0)
source
ColorSchemeTools.add_alphaMethod
add_alpha(cs::ColorScheme, f::Function)

Make a copy of the colorscheme cs with alpha opacity values defined by the function.

Example

Make a copy of the PuOr colorscheme, set the opacity of each element to be the result of calling the function on the value. So at value 0.5, the opacity is 1.0, but it's 0.0 at either end.

add_alpha(ColorSchemes.PuOr, (n) -> sin(n * π))
source
ColorSchemeTools.add_alphaMethod
add_alpha(cs::ColorScheme, alpha::Vector)

Make a copy of the colorscheme cs with alpha opacity values in the vector alpha.

Example

Make a copy of the PuOr colorscheme, set the first element to have alpha opacity 1.0, the last element to have opacity 0.0, with intermediate elements taking values between 1.0 and 0.0.

add_alpha(ColorSchemes.PuOr, [1.0, 0.0])
source
ColorSchemeTools.colorscheme_to_imageFunction
colorscheme_to_image(cs, nrows=50, tilewidth=5)

Make an image from a ColorScheme by repeating the colors in nrows rows, repeating each pixel tilewidth times.

Returns the image as an array.

Examples:

using FileIO

img = colorscheme_to_image(ColorSchemes.leonardo, 50, 200)
save("/tmp/cs_image.png", img)

save("/tmp/blackbody.png", colorscheme_to_image(ColorSchemes.blackbody, 10, 100))
source
ColorSchemeTools.colorscheme_to_textMethod
colorscheme_to_text(cscheme::ColorScheme, schemename, filename;
    category="dutch painters",   # category
    notes="it's not really lost" # notes
)

Write a ColorScheme to a Julia text file.

Example

colorscheme_to_text(ColorSchemes.vermeer,
    "the_lost_vermeer",          # name
    "/tmp/the_lost_vermeer.jl",  # file
    category="dutch painters",   # category
    notes="it's not really lost" # notes
    )

and read it back in with:

include("/tmp/the_lost_vermeer.jl")
source
ColorSchemeTools.colorscheme_weightedFunction
colorscheme_weighted(colorscheme, weights, length)

Returns a new ColorScheme of length length (default 50) where the proportion of each color in colorscheme is represented by the associated weight of each entry.

Examples:

colorscheme_weighted(extract_weighted_colors("hokusai.jpg")...)
colorscheme_weighted(extract_weighted_colors("filename00000001.jpg")..., 500)
source
ColorSchemeTools.compare_colorsFunction
compare_colors(color_a, color_b, field = :l)

Compare two colors, using the Luv colorspace. field defaults to luminance :l but could be :u or :v. Return true if the specified field of color_a is less than color_b.

source
ColorSchemeTools.convert_to_schemeMethod
convert_to_scheme(cscheme, img)

Converts img from its current color values to use only the colors defined in the ColorScheme cscheme.

image = nonTransparentImg
convert_to_scheme(ColorSchemes.leonardo, image)
convert_to_scheme(ColorSchemes.Paired_12, image)
source
ColorSchemeTools.equalizeMethod
equalize(cs::ColorScheme;
    colormodel::Symbol="RGB",
    formula::String="CIE76",
    W::Array=[1.0, 0.0, 0.0],
    sigma::Real=0.0,
    cyclic::Bool=false)

equalize(ca::Array{Colorant, 1}; 
    # same keywords 
    )

Equalize colors in the colorscheme cs or the array of colors ca so that they are more perceptually uniform.

  • cs is a ColorScheme

  • ca is an array of colors

  • colormodelis:RGBor:LAB`

  • formula is "CIE76" or "CIEDE2000"

  • W is a vector of three weights to be applied to the lightness, chroma, and hue components of the difference equation

  • sigma is an optional Gaussian smoothing parameter

  • cyclic is a Boolean flag indicating whether the colormap is cyclic

Returns a colorscheme with the colors adjusted.

source
ColorSchemeTools.extractFunction
extract(imfile, n=10, i=10, tolerance=0.01; shrink=n)

extract() extracts the most common colors from an image from the image file imfile by finding n dominant colors, using i iterations. You can (and probably should) shrink larger images before running this function.

Returns a ColorScheme.

source
ColorSchemeTools.extract_weighted_colorsFunction
extract_weighted_colors(imfile, n=10, i=10, tolerance=0.01; shrink = 2)

Extract colors and weights of the clusters of colors in an image file. Returns a ColorScheme and weights.

Example:

pal, wts = extract_weighted_colors(imfile, n, i, tolerance; shrink = 2)
source
ColorSchemeTools.get_indexed_list_colorMethod
get_indexed_list_color(indexedlist, n)

Get the color at a point n given an indexed list of triples like this:

gist_rainbow = (
       (0.000,   (1.00, 0.00, 0.16)),
       (0.030,   (1.00, 0.00, 0.00)),
       (0.215,   (1.00, 1.00, 0.00)),
       (0.400,   (0.00, 1.00, 0.00)),
       (0.586,   (0.00, 1.00, 1.00)),
       (0.770,   (0.00, 0.00, 1.00)),
       (0.954,   (1.00, 0.00, 1.00)),
       (1.000,   (1.00, 0.00, 0.75))
    )

To make a ColorScheme from this type of list, use:

make_colorscheme(gist_rainbow)
source
ColorSchemeTools.get_linear_segment_colorMethod
get_linear_segment_color(dict, n)

Get the RGB color for value n from a dictionary of linear color segments.

This following is a dictionary where red increases from 0 to 1 over the bottom half, green does the same over the middle half, and blue over the top half:

cdict = Dict(:red  => ((0.0,  0.0,  0.0),
                       (0.5,  1.0,  1.0),
                       (1.0,  1.0,  1.0)),
            :green => ((0.0,  0.0,  0.0),
                       (0.25, 0.0,  0.0),
                       (0.75, 1.0,  1.0),
                       (1.0,  1.0,  1.0)),
            :blue =>  ((0.0,  0.0,  0.0),
                       (0.5,  0.0,  0.0),
                       (1.0,  1.0,  1.0)))

The value of RGB component at every value of n is defined by a set of tuples. In each tuple, the first number is x. Colors are linearly interpolated in bands between consecutive values of x; if the first tuple is given by (Z, A, B) and the second tuple by (X, C, D), the color of a point n between Z and X will be given by (n - Z) / (X - Z) * (C - B) + B.

For example, given an entry like this:

:red  => ((0.0, 0.0, 0.0),
          (0.5, 1.0, 1.0),
          (1.0, 1.0, 1.0))

and if n = 0.75, we return 1.0; 0.75 is between the second and third segments, but we'd already reached 1.0 (segment 2) when n was 0.5.

source
ColorSchemeTools.image_to_swatchMethod
image_to_swatch(imagefilepath, samples, destinationpath;
    nrows=50,
    tilewidth=5)

Extract a ColorsSheme from the image in imagefilepath to a swatch image PNG in destinationpath. This just runs sortcolorscheme(), colorscheme_to_image(), and save() in sequence.

Specify the number of colors. You can also specify the number of rows, and how many times each color is repeated.

image_to_swatch("monalisa.jpg", 10, "/tmp/monalisaswatch.png")
source
ColorSchemeTools.lerpFunction
lerp((x, from_min, from_max, to_min=0.0, to_max=1.0)

Linear interpolation of x between from_min and from_max.

Example

ColorSchemeTools.lerp(128, 0, 256)
0.5
source
ColorSchemeTools.make_colorschemeMethod
make_colorscheme(f1::Function, f2::Function, f3::Function, f4::Function;
    model    = :RGBA,
    length   = 100,
    category = "",
    notes    = "functional ColorScheme")

Make a colorscheme with transparency using functions. Each argument is a function that returns a value for the red, green, blue, and alpha components for the values between 0 and 1.

model is the color model, and can be :RGBA, :HSVA, or :LCHabA.

Use length keyword to set the number of colors in the colorscheme.

The default color mo del is :RGBA, and the functions should return values in the appropriate range:

  • f1 - [0.0 - 1.0] - red
  • f2 - [0.0 - 1.0] - green
  • f3 - [0.0 - 1.0] - blue
  • f4 - [0.0 - 1.0] - alpha

For the :HSVA color model:

  • f1 - [0.0 - 360.0] - hue
  • f2 - [0.0 - 1.0] - saturataion
  • f3 - [0.0 - 1.0] - value (brightness)
  • f4 - [0.0 - 1.0] - alpha

For the :LCHabA color model:

  • f1 - [0.0 - 100.0] - luminance
  • f2 - [0.0 - 100.0] - chroma
  • f3 - [0.0 - 360.0] - hue
  • f4 - [0.0 - 1.0] - alpha

Examples

csa = make_colorscheme1(
    n -> red(get(ColorSchemes.leonardo, n)),
    n -> green(get(ColorSchemes.leonardo, n)),
    n -> blue(get(ColorSchemes.leonardo, n)),
    n -> 1 - identity(n))
source
ColorSchemeTools.make_colorschemeMethod
make_colorscheme(colorlist, steps)

Make a new colorscheme consisting of the colors in the array colorlist.

make_colorscheme([RGB(1, 0, 0), HSB(285, 0.7, 0.7), colorant"darkslateblue"], 20)
source
ColorSchemeTools.make_colorschemeMethod
make_colorscheme(dict;
    length=100,
    category="",
    notes="")

Make a new ColorScheme from a dictionary of linear-segment information. Calls get_linear_segment_color(dict, n) with n for every length value between 0 and 1.

source
ColorSchemeTools.make_colorschemeMethod
make_colorscheme(f1::Function, f2::Function, f3::Function;
    model    = :RGB,
    length   = 100,
    category = "",
    notes    = "functional ColorScheme")

Make a colorscheme using functions. Each argument is a function that returns a value for the red, green, and blue components for the values between 0 and 1.

model is the color model, and can be :RGB, :HSV, or :LCHab.

Use length keyword to set the number of colors in the colorscheme.

The default color model is :RGB, and the functions should return values in the appropriate range:

  • f1 - [0.0 - 1.0] - red
  • f2 - [0.0 - 1.0] - green
  • f3 - [0.0 - 1.0] - blue

For the :HSV color model:

  • f1 - [0.0 - 360.0] - hue
  • f2 - [0.0 - 1.0] - saturataion
  • f3 - [0.0 - 1.0] - value (brightness)

For the :LCHab color model:

  • f1 - [0.0 - 100.0] - luminance
  • f2 - [0.0 - 100.0] - chroma
  • f3 - [0.0 - 360.0] - hue

Example

Make a colorscheme with the red component defined as a sine curve running from 0 to π and back to 0, the green component is always 0, and the blue component starts at π and goes to 0 at 0.5 (it's clamped to 0 after that).

make_colorscheme(n -> sin(n * π), n -> 0, n -> cos(n * π))
source
ColorSchemeTools.make_colorschemeMethod
make_colorscheme(indexedlist;
    length=length(indexedlist),
    category="",
    notes="")

Make a ColorScheme using an 'indexed list' like this:

gist_rainbow = (
       (0.000, (1.00, 0.00, 0.16)),
       (0.030, (1.00, 0.00, 0.00)),
       (0.215, (1.00, 1.00, 0.00)),
       (0.400, (0.00, 1.00, 0.00)),
       (0.586, (0.00, 1.00, 1.00)),
       (0.770, (0.00, 0.00, 1.00)),
       (0.954, (1.00, 0.00, 1.00)),
       (1.000, (1.00, 0.00, 0.75))
)

make_colorscheme(gist_rainbow)

The first element of each item is the point on the colorscheme.

Use length keyword to set the number of colors in the colorscheme.

source
ColorSchemeTools.sinerampMethod
sineramp(rows, cols;
        amplitude = 12.5,
        wavelength = 8,
        p = 2)

Generate a rows × cols array of values which show a sine wave with decreasing amplitude from top to bottom.

Usage:

using Images
scheme = ColorSchemes.dracula
img = Gray.(sineramp(256, 512, amp = 12.5, wavelen = 8, p = 2))
cimg = zeros(RGB, 256, 512)
for e in eachindex(img)
    cimg[e] = get(mscheme, img[e])
end
cimg

The default wavelength is 8 pixels. On a computer monitor with a nominal pixel pitch of 0.25mm this corresponds to a wavelength of 2mm. With a monitor viewing distance of 600mm this corresponds to 0.19 degrees of viewing angle or approximately 5.2 cycles per degree. This falls within the range of spatial frequencies (3-7 cycles per degree) at which most people have maximal contrast sensitivity to a sine wave grating (this varies with mean luminance). A wavelength of 8 pixels is also sufficient to provide a reasonable discrete representation of a sine wave. The aim is to present a stimulus that is well matched to the performance of the human visual system so that what we are primarily evaluating is the colorscheme's perceptual contrast and not the visual performance of the viewer.

The default amplitude is set at 12.5, so that from peak to trough we have a local feature of magnitude 25. This is approximately 10% of the 256 levels in a typical colorscheme. It is not uncommon for colorschemes to have perceptual flat spots that can hide features of this magnitude.

The width of the image is adjusted so that we have an integer number of cycles of the sinewave. This helps should one be using the test image to evaluate a cyclic colorscheme. However you will still see a slight cyclic discontinuity at the top of the image, though this will disappear at the bottom.

source
ColorSchemeTools.sortcolorschemeFunction
sortcolorscheme(colorscheme::ColorScheme, field; kwargs...)

Sort (non-destructively) a colorscheme using a field of the LUV colorspace.

The less than function is lt = (x,y) -> compare_colors(x, y, field).

The default is to sort by the luminance field :l but could be by :u or :v.

Returns a new ColorScheme.

source