Skip to content

Commit

Permalink
Support dict as label_names in label2rgb
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Jan 31, 2021
1 parent dbe4faf commit 6ec18db
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions imgviz/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def label2rgb(
RGB image.
alpha: float
Alpha of RGB (default: 0.5).
label_names: list of string
label_names: list or dict of string
Label id to label name.
font_size: int
Font size (default: 30).
Expand Down Expand Up @@ -111,7 +111,10 @@ def label2rgb(

unique_labels = np.unique(label)
unique_labels = unique_labels[unique_labels != -1]
unique_labels = [l for l in unique_labels if label_names[l] is not None]
if isinstance(label_names, dict):
unique_labels = [l for l in unique_labels if label_names.get(l)]
else:
unique_labels = [l for l in unique_labels if label_names[l]]
if len(unique_labels) == 0:
return res

Expand Down

0 comments on commit 6ec18db

Please sign in to comment.