neurotools.graphics.color module
Miscellaneous color-related functions.
- neurotools.graphics.color.hsv2rgb(h, s, v, force_luminance=None, method='perceived')[source]
Convert HSV colors to RGB
- Parameters:
h (hue 0 to 360)
s (saturation 0 to 1)
v (value 0 to 1)
- Returns:
r,g,b
- Return type:
RGB tuple
- neurotools.graphics.color.lightness(r, g, b, method='lightness')[source]
- Parameters:
r (red)
g (green)
b (blue)
method (str) – Can be ‘perceived’, ‘standard’, or ‘lightness’. ‘lightness’ is the default
- Returns:
M – Weights to convert RGB vectors into a luminance value.
- Return type:
np.ndarray
- neurotools.graphics.color.luminance_matrix(method='perceived')[source]
Method ‘perceived’: .299*R + .587*G + .114*B Method ‘standard’ : .2126*R + .7152*G + .0722*B Method ‘lightness’: .3*R + .59*G + .11*B
- Parameters:
method (str) – Can be ‘perceived’, ‘standard’, or ‘lightness’. ‘perceived’ is the default.
- Returns:
LRGB – Weights for converting RGB vectors to scalar luminance values.
- Return type:
np.array
- neurotools.graphics.color.match_luminance(target, color, THRESHOLD=0.01, squared=False, method='perceived')[source]
Adjust color to match luminosity of target
Method ‘perceived’ .299*R + .587*G + .114*B Method ‘standard’ .2126*R + .7152*G + .0722*B Method ‘lightness’ .3*R + .59*G + .11*B
- Parameters:
target
color
THRESHOLD (0.01)
squared (False)
method ('perceived')
- Return type:
color
- neurotools.graphics.color.rotate(colors, th)[source]
Rotate a list of rgb colors by angle theta
- Parameters:
colors (array-like) – Iterable of (r,g,b) tuples. Rotation does not affect magnitude, but may cause resulting colors to fall outside original colorspace.
th (float) – Angle to rotate
- Returns:
list – List of hue-rotated (r,g,b) tuples
- Return type:
results
- neurotools.graphics.color.RGBtoHCL(r, g, b, method='perceived')[source]
Convert RGB colors to Hue, Chroma, Luminance color space
- Parameters:
r
g
b
- Returns:
hue
chroma
luminance
- neurotools.graphics.color.hue_angle(c1, c2)[source]
Calculates the angular difference in hue between two colors in Hue, Chroma, Luminance (HCL) colorspace.
- Parameters:
c1 (first color)
c2 (second color)
- Return type:
hue angle diference
- neurotools.graphics.color.hcl2rgb(h, c, l, target=None, method='perceived')[source]
- Parameters:
h (hue in degrees)
c (chroma)
l (luminosity)
- Returns:
RGB – Length-3 numpy array of RGB color components
- Return type:
ndarray
- neurotools.graphics.color.circularly_smooth_colormap(cm, s)[source]
Smooth a colormap with cirular boundary conditions
s: sigma, standard dev of gaussian smoothing kernel in samples cm: color map, array-like of RGB tuples
- Parameters:
cm (colormap)
s (smoothing radius)
- Returns:
RBG – Colormap smoothed with circular boundary conditions.
- Return type:
np.ndarray
- neurotools.graphics.color.radl2rgb(h, l=1.0)[source]
Slightly more optimized HSL conversion routine. Saturation fixed at 1
- neurotools.graphics.color.radl2rgbLUT(h, l=1.0)[source]
radl2rgb backed with a limited resolution lookup table
- neurotools.graphics.color.complexHLArr2RGB(z)[source]
Performs bulk LUT for complex numbers, avoids loops
- neurotools.graphics.color.color_boxplot(bp, COLOR)[source]
The Boxplot defaults are awful. This is a little better
- neurotools.graphics.color.hex_pack_BGR(RGB)[source]
Packs RGB colors data in hexadecimal BGR format for fast rendering to Javascript canvas.
This is useful for importing color-maps into HTML and javascript demos.
- Parameters:
RGB (256x3 array-like) – RGB values
- Returns:
List of HTML hex codes for the given RGB colors
- Return type:
list
- neurotools.graphics.color.code_to_16bit(code)[source]
Converts a #RRGGBB hex code into a 16-bit packed 565 BRG integer form
- neurotools.graphics.color.bit16_RGB_to_tuple(RGB)[source]
Converts 16-bit RRRRR GGGGGG BBBBB into (R,G,B) tuple form
- Parameters:
RGB (int) – 16-bit RRRRR GGGGGG BBBBB packed color
- Returns:
Components in [0,1]
- Return type:
R,G,B
- neurotools.graphics.color.enumerate_fast_colors()[source]
This is for the Arduino TFT touch screen shield from Adafruit.
Enumerates colors that can be rendered over a 16 bit bus using two identical bytes, skipping the lowest two bits of each byte, and reserving the fourth bit for mask storage. This is intended for development of optimized color pallets for mictrocontroller driven display interfaces.
- Returns:
colors
- Return type:
list
- neurotools.graphics.color.tuple_to_bit16(c)[source]
convert RGB float tuple in 565 bit packed RGB format
- Parameters:
c (RGB color tuple)
- Returns:
RGB
- Return type:
int
- neurotools.graphics.color.tuple_to_bit24(c)[source]
convert RGB float tuple in 565 bit packed RGB format
- Parameters:
c (RGB color tuple)
- neurotools.graphics.color.bit16_print_color(c)[source]
Convert RGB tuple to 16 bit 565 RGB formt as a binary string literal
- Parameters:
c (RGB color tuple)
- Return type:
bin(tuple_to_bit16(c))
- neurotools.graphics.color.show_fast_pallet()[source]
Subset of colors that can be shownn quickly on the Arduino UNO using the standard 3.2-inch TFT touch-screen breakout. Restricts colors that can be sent with a single write to one port. 16-bit color mode with low and high bytes identical.
- neurotools.graphics.color.show_complete_fastest_pallet()[source]
16 bit RGB 565; but don’t even write the lower byte
- neurotools.graphics.color.show_hex_pallet(colors)[source]
- Parameters:
colors (list of colors to show)
- neurotools.graphics.color.lighten(color, amount=0.2)[source]
Ligten a color by blending it with white.
- Parameters:
color (matplotlib.color) – Matplotlib color to lighten
amount (float in [0,1]; default 0.2) – Amount of white to blend with color
- Returns:
Length-3 RGB tuple. Alpha is discarded.
- Return type:
np.float32
- neurotools.graphics.color.darken(color, amount=0.2)[source]
Darken a color by blending it with black.
- Parameters:
color (matplotlib.color) – Matplotlib color to lighten
amount (float in [0,1]; default 0.2) – Amount of black to blend with color
- Returns:
Length-3 RGB tuple. Alpha is discarded.
- Return type:
np.float32