Goulib.colors module¶
color conversion in various colorspaces and palettes
-
Goulib.colors.rgb2cmyk(rgb, **kwargs)[source]¶ Parameters: rgb – 3-tuple of floats of red,green,blue in [0..1] range Returns: 4-tuple of floats (cyan, magenta, yellow, black) in [0..1] range
-
Goulib.colors.cmyk2rgb(cmyk, **kwargs)[source]¶ Parameters: cmyk – 4-tuple of floats (cyan, magenta, yellow, black) in [0..1] range Result: 3-tuple of floats (red,green,blue) warning : rgb is out the [0..1] range for some cmyk
-
Goulib.colors.xyz2xyy(xyz, **kwargs)[source]¶ Convert from XYZ to xyY
Based on formula from http://brucelindbloom.com/Eqn_XYZ_to_xyY.html
Implementation Notes: 1. Watch out for black, where X = Y = Z = 0. In that case, x and y are set
to the chromaticity coordinates of the reference whitepoint.- The output Y value is in the nominal range [0.0, Y[XYZ]].
-
Goulib.colors.xyy2xyz(xyY, **kwargs)[source]¶ Convert from xyY to XYZ to
Based on formula from http://brucelindbloom.com/Eqn_xyY_to_XYZ.html
Implementation Notes:
- Watch out for the case where y = 0. In that case, you may want to set X = Y = Z = 0.
- The output XYZ values are in the nominal range [0.0, 1.0].
-
Goulib.colors.converter(c, illuminant='ignore')¶
-
Goulib.colors.convert(color, source, target)[source]¶ convert a color between colorspaces, eventually using intermediary steps
-
class
Goulib.colors.Color(value, space='RGB', name=None, illuminant='D65')[source]¶ Bases:
objectA color with math operations and conversions Color is immutable (._values caches representations)
constructor :param value: string color name, hex string, or values tuple :param space: string defining the color space of value :param name: string for color name :param illuminant: string in {“A”, “D50”, “D55”, “D65”, “D75”, “E”}
- D65 is used by default in skimage, see http://scikit-image.org/docs/dev/api/skimage.color.html
- D50 is used in Pantone and other graphic arts
-
__init__(value, space='RGB', name=None, illuminant='D65')[source]¶ constructor :param value: string color name, hex string, or values tuple :param space: string defining the color space of value :param name: string for color name :param illuminant: string in {“A”, “D50”, “D55”, “D65”, “D75”, “E”}
- D65 is used by default in skimage, see http://scikit-image.org/docs/dev/api/skimage.color.html
- D50 is used in Pantone and other graphic arts
-
name¶
-
convert(target, **kwargs)[source]¶ Parameters: target – str of desired colorspace, or none for default Returns: color in target colorspace
-
native¶
-
rgb¶
-
hex¶
-
lab¶
-
luv¶
-
cmyk¶
-
hsv¶
-
xyz¶
-
xyY¶
-
deltaE(other)[source]¶ color difference according to CIEDE2000 https://en.wikipedia.org/wiki/Color_difference
-
isclose(other, abs_tol=1)[source]¶ http://zschuessler.github.io/DeltaE/learn/ <= 1.0 Not perceptible by human eyes. 1 - 2 Perceptible through close observation. 2 - 10 Perceptible at a glance. 11 - 49 Colors are more similar than opposite 100 Colors are exact opposite
-
__class__¶ alias of
builtins.type
-
__delattr__¶ Implement delattr(self, name).
-
__dir__()¶ Default dir() implementation.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__gt__¶ Return self>value.
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Helper for pickle.
-
__reduce_ex__()¶ Helper for pickle.
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__()¶ Size of object in memory, in bytes.
-
__str__¶ Return str(self).
-
class
Goulib.colors.Palette(data=[], keys=256)[source]¶ Bases:
collections.OrderedDictdict of Colors indexed by anything
-
update(data, keys=256)[source]¶ updates the dictionary with new colors :param data: colors to add :param keys: keys to use in dict, or int to discretize the Colormap
-
pil¶ Returns: a sequence of integers, or a string containing a binary representation of the palette. In both cases, the palette contents should be ordered (r, g, b, r, g, b, …). The palette can contain up to 768 entries (3*256). If a shorter palette is given, it is padded with zeros. #http://effbot.org/zone/creating-palette-images.htm
-
__class__¶ alias of
builtins.type
-
__contains__()¶ True if the dictionary has the specified key, else False.
-
__delattr__¶ Implement delattr(self, name).
-
__delitem__¶ Delete self[key].
-
__dir__()¶ Default dir() implementation.
-
__eq__¶ Return self==value.
-
__format__()¶ Default object formatter.
-
__ge__¶ Return self>=value.
-
__getattribute__¶ Return getattr(self, name).
-
__getitem__()¶ x.__getitem__(y) <==> x[y]
-
__gt__¶ Return self>value.
-
__hash__= None¶
-
__init_subclass__()¶ This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
-
__iter__¶ Implement iter(self).
-
__le__¶ Return self<=value.
-
__len__¶ Return len(self).
-
__lt__¶ Return self<value.
-
__ne__¶ Return self!=value.
-
__new__()¶ Create and return a new object. See help(type) for accurate signature.
-
__reduce__()¶ Return state information for pickling
-
__reduce_ex__()¶ Helper for pickle.
-
__reversed__() <==> reversed(od)¶
-
__setattr__¶ Implement setattr(self, name, value).
-
__setitem__¶ Set self[key] to value.
-
__sizeof__() → size of D in memory, in bytes¶
-
__str__¶ Return str(self).
-
clear() → None. Remove all items from od.¶
-
copy() → a shallow copy of od¶
-
fromkeys()¶ Create a new ordered dictionary with keys from iterable and values set to value.
-
get()¶ Return the value for key if key is in the dictionary, else default.
-
items() → a set-like object providing a view on D's items¶
-
keys() → a set-like object providing a view on D's keys¶
-
move_to_end()¶ Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.
-
pop(k[, d]) → v, remove specified key and return the corresponding¶ value. If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem()¶ Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
-
setdefault()¶ Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
-
values() → an object providing a view on D's values¶
-
-
Goulib.colors.nearest_color(c, l=None, opt=<built-in function min>, comp=<function deltaE>)[source]¶ Parameters: - x – Color
- l – list or dict of Color, color by default
- opt – with opt=max you can find the most different color …
Returns: nearest Color of x in l
-
Goulib.colors.color_range(n, start, end, space='hsv')[source]¶ Parameters: - n – int number of colors to generate
- start – string hex color or color name
- end – string hex color or color name
Result: list of n Color interpolated between start and end, included
-
Goulib.colors.blackBody2Color(tempK)[source]¶ Parameters: wavelength – black body temperature in K (Sun is 5780) Result: Color