Skip to content
Snippets Groups Projects

Rand cmap

2 files
+ 22
17
Compare changes
  • Side-by-side
  • Inline

Files

@@ -6,7 +6,7 @@ from matplotlib.colors import LinearSegmentedColormap
from qim3d.io.logger import log
def qim3dCmap(nlabels, type="bright", first_color_black=True, last_color_black=False):
def qim3dCmap(nlabels, type="bright", first_color_black=True, last_color_black=False,seed=19):
"""
Creates a random colormap to be used together with matplotlib. Useful for segmentation tasks
@@ -15,6 +15,7 @@ def qim3dCmap(nlabels, type="bright", first_color_black=True, last_color_black=F
type (str, optional): 'bright' for strong colors, 'soft' for pastel colors. Defaults to 'bright'.
first_color_black (bool, optional): Option to use first color as black. Defaults to True.
last_color_black (bool, optional): Option to use last color as black. Defaults to False.
seed (int, optional): Seed for random number generator. Defaults to 19.
Returns:
matplotlib.colors.LinearSegmentedColormap: Colormap for matplotlib
@@ -24,12 +25,14 @@ def qim3dCmap(nlabels, type="bright", first_color_black=True, last_color_black=F
return
# Generate color map for bright colors, based on hsv
# Create a new random generator, to locally set seed
rng = np.random.default_rng(seed)
if type == "bright":
randHSVcolors = [
(
np.random.uniform(low=0.0, high=1),
np.random.uniform(low=0.2, high=1),
np.random.uniform(low=0.9, high=1),
rng.uniform(low=0.0, high=1),
rng.uniform(low=0.2, high=1),
rng.uniform(low=0.9, high=1),
)
for i in range(nlabels)
]
@@ -57,9 +60,9 @@ def qim3dCmap(nlabels, type="bright", first_color_black=True, last_color_black=F
high = 0.95
randRGBcolors = [
(
np.random.uniform(low=low, high=high),
np.random.uniform(low=low, high=high),
np.random.uniform(low=low, high=high),
rng.uniform(low=low, high=high),
rng.uniform(low=low, high=high),
rng.uniform(low=low, high=high),
)
for i in range(nlabels)
]
Loading