Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doctr/utils/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ def get_colors(num_colors: int) -> list[tuple[float, float, float]]:
colors: list of generated colors
"""
colors = []
for i in np.arange(0.0, 360.0, 360.0 / num_colors):
hue = i / 360.0
# Integer steps give exactly num_colors hues (a float step can add one more, close to 360°, i.e. red again)
for i in range(num_colors):
hue = i / num_colors
lightness = (50 + np.random.rand() * 10) / 100.0
saturation = (90 + np.random.rand() * 10) / 100.0
colors.append(colorsys.hls_to_rgb(hue, lightness, saturation))
Expand Down
7 changes: 7 additions & 0 deletions tests/common/test_utils_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ def test_visualize_kie_page():
assert len(fig.axes[0].texts) == 0


@pytest.mark.parametrize("num_colors", [0, 1, 3, 161, 175])
def test_get_colors(num_colors):
colors = visualization.get_colors(num_colors)
assert len(colors) == num_colors
assert all(len(color) == 3 and all(0 <= c <= 1 for c in color) for color in colors)


def test_draw_boxes():
image = np.ones((256, 256, 3), dtype=np.float32)
boxes = [
Expand Down
Loading