Skip to content

Commit aa7b6db

Browse files
committed
Update readme, docstrings
1 parent 84163d4 commit aa7b6db

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021-23 Myungchul Keum
3+
Copyright (c) 2021 Myungchul Keum
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ A perceptually uniform colormaps with **full range of lightness**.
55

66
## Preview
77

8-
![roseus-bars](img/roseus-bars.png)
8+
![Colorbars](img/roseus-bars.png)
99

10-
![audacity-roseus](img/audacity-roseus.png)
10+
![Audio spectrogram using Roseus](img/audacity-roseus.png)
11+
12+
![Depth map using Arcus](img/depthmap-arcus.png)
1113

1214

1315
## Installation
@@ -16,7 +18,7 @@ A perceptually uniform colormaps with **full range of lightness**.
1618
pip install roseus
1719
```
1820

19-
If installation fails, upgrade pip with python -m pip install --upgrade pip and try again.
21+
If installation fails, upgrade pip with `python -m pip install --upgrade pip` and try again.
2022

2123

2224
## Usage
@@ -27,9 +29,9 @@ To use with matplotlib, import `roseus.mpl`.
2729
import matplotlib.pyplot as plt
2830
import roseus.mpl as rs
2931

30-
plt.imshow(x, cmap=rs.roseus)
32+
plt.imshow(x, cmap=rs.arcus)
3133
# or
32-
plt.imshow(x, cmap='rs.roseus')
34+
plt.imshow(x, cmap='rs.arcus')
3335
```
3436

3537
To prevent confusion in namespace, prefix `rs.` is added. (ex. `rs.arcus`, `rs.b`, `rs.gr`, ...)
@@ -49,6 +51,10 @@ https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html
4951
## Look into the colormaps
5052

5153
To plot measures of a colormap in Roseus family,
54+
```sh
55+
pip install "roseus[generate]"
56+
```
57+
install additional dependency. Then,
5258

5359
```python
5460
from roseus.util import plot_measures

img/audacity-roseus.png

-362 KB
Loading

img/depthmap-arcus.png

436 KB
Loading

optimize_colormap.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
import numpy as np
1212
from scipy.ndimage import maximum_filter
1313

14-
from roseus import gen_colormap
14+
import roseus.mpl as rs
15+
from roseus.generator import gen_colormap
1516

1617

1718
def batch_colormap(tasks):
1819
results = []
1920
for task in tasks:
20-
_, score = gen_colormap(task, lightness_range=(3, 97))
21+
_, score = gen_colormap(task, chroma_shape='sin', lightness_range=(2, 98))
2122
results.append(score)
2223
return results
2324

@@ -47,7 +48,7 @@ def batch_colormap(tasks):
4748

4849
arc_scores = np.asarray(results, dtype=np.float32)
4950

50-
plt.imshow(arc_scores.T, extent=(sr[0], sr[1], rr[1], rr[0]), interpolation='none')
51+
plt.imshow(arc_scores.T, extent=(sr[0], sr[1], rr[1], rr[0]), interpolation='none', cmap=rs.roseus)
5152

5253
max_index = np.unravel_index(arc_scores.argmax(), arc_scores.shape)
5354
print(max_index)

roseus/generator.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Roseus colormap generator
44
https://github.com/dofuuz/roseus
55
6-
Roseus: A perceptually uniform colormap with full range of lightness
6+
Roseus: Perceptually uniform colormaps with full range of lightness
77
"""
88

99
import bisect
@@ -20,6 +20,27 @@
2020

2121

2222
def gen_colormap(hue_range=(-185, 170), chroma_shape='cos', lightness_range=(2, 99), plots=False):
23+
""" Generate a perceptually uniform colormap has symmetric and smooth chroma, hue transition.
24+
25+
Parameters
26+
----------
27+
hue_range : tuple
28+
Hue range in degrees.
29+
chroma_shape :
30+
Shape of chroma transition.
31+
One of 'sin', 'circle', 'cos'.
32+
lightness_range : tuple
33+
Lightness range
34+
plots :
35+
Set `True` to print details.
36+
Set 'verbose' to print additional measures.
37+
38+
Returns
39+
-------
40+
Tuple of (color_rgb, score).
41+
`color_rgb` is RGB values of the colormap.
42+
`score` is value represents how much colormap is colorful.
43+
"""
2344
rx = np.linspace(0, 1, RES)
2445

2546
if chroma_shape == 'square':
@@ -96,8 +117,8 @@ def in_gamut(c_mul):
96117
arc_len = sum_len * c_mul * (lightness_range[1] - lightness_range[0])
97118

98119
if plots:
99-
print(c_mul)
100-
print(arc_len)
120+
print(f'Max chroma: {c_mul}')
121+
print(f'Length of variation: {arc_len}')
101122

102123
if plots == 'verbose':
103124
plot_jch(j, c_, h_)
@@ -107,7 +128,7 @@ def in_gamut(c_mul):
107128

108129

109130
def plot_jch(j, c_, h_):
110-
# plot J, C, h
131+
""" Plot transition of Lightness, Chroma, Hue """
111132
plt.figure(figsize=(6.4, 3.6))
112133

113134
ax = plt.subplot(231)
@@ -144,6 +165,7 @@ def plot_jch(j, c_, h_):
144165

145166

146167
def plot_gamut(jab):
168+
""" Plot sRGB gamut for colormaps. It is broken for most of colormaps for now."""
147169
j = jab[..., 0]
148170
a = jab[..., 1]
149171
b = jab[..., 2]
@@ -184,6 +206,7 @@ def plot_gamut(jab):
184206

185207

186208
def plot_rgb(rgb1):
209+
""" Plot RGB values """
187210
rgbs = (rgb1*255).round().clip(0, 255).astype('uint8')
188211

189212
seg_simple = 8

0 commit comments

Comments
 (0)