Segment Colors#

Python implementation of neuroglancer’s pseudo-random segment color generator.

Adapted from Austin Hoag’s implementation. This version is lightly refactored to support JIT-compilation and vectorization using numba.

See also: The source code here in segmentcolors.py also includes a WebGL implementation of the same algorithm, suitable for neuroglancer annotation shaders.

ngsidekick.segmentcolors.hex_string_from_segment_id(color_seed, segment_id)[source]#

Return the hex color string for a segment given a color seed and the segment id.

If color_seed and/or segment_id is an array, then they’ll be broadcasted together and a list of colors will be returned.

ngsidekick.segmentcolors.rgb_from_segment_id(color_seed, segment_id)[source]#

Hash the segment_id to an RGB array of uint8 according to the given color_seed.

If color_seed and/or segment_id is an array, then they’ll be broadcasted together and a list of colors will be returned.

ngsidekick.segmentcolors.unpack_color(packed_color)[source]#

Unpack an array of packed colors with shape (…,) into an array of shape (…, 3) with r,g,b in the last dimension. Also works for a single packed color scalar.

ngsidekick.segmentcolors.pack_color(rgb_vec)[source]#

Returns an integer formed by concatenating the channels of the input color vector. Python implementation of packColor in src/neuroglancer/util/color.ts

ngsidekick.segmentcolors.hash_function(state, value)[source]#

Python implementation of hashCombine() function in src/neuroglancer/gpu_hash/hash_function.ts, a modified murmur hash

ngsidekick.segmentcolors.hsv_to_rgb(h, s, v)[source]#

Convert H,S,V values to RGB values. Python implementation of hsvToRgb in src/neuroglancer/util/colorspace.ts

Overview#

Tools for managing and applying colors to segments in Neuroglancer.