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:
object
A 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
-
__delattr__
¶ Implement delattr(self, name).
-
__dir__
() → list¶ default dir() implementation
-
__format__
()¶ default object formatter
-
__ge__
¶ Return self>=value.
-
__getattribute__
¶ Return getattr(self, name).
-
__gt__
¶ Return self>value.
-
__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__
() → int¶ size of object in memory, in bytes
-
__str__
¶ Return str(self).
-
class
Goulib.colors.
Palette
(data=[], keys=256)[source]¶ Bases:
collections.OrderedDict
dict 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
-
__contains__
()¶ True if D has a key k, else False.
-
__delattr__
¶ Implement delattr(self, name).
-
__delitem__
¶ Delete self[key].
-
__dir__
() → list¶ 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¶
-
__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__
()¶
-
__str__
¶ Return str(self).
-
clear
() → None. Remove all items from od.¶
-
copy
() → a shallow copy of od¶
-
fromkeys
(S[, v]) → New ordered dictionary with keys from S.¶ If not specified, the value defaults to None.
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
items
()¶
-
keys
()¶
-
move_to_end
()¶ Move an existing element to the end (or beginning if last==False).
Raises KeyError if the element does not exist. When last=True, acts like a fast version of self[key]=self.pop(key).
-
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
() → (k, v), return and remove a (key, value) pair.¶ Pairs are returned in LIFO order if last is true or FIFO order if false.
-
setdefault
(k[, d]) → od.get(k,d), also set od[k]=d if k not in od¶
-
values
()¶
-