Skip to content

Commit

Permalink
Skip label_name which is None
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Apr 29, 2020
1 parent 17f3ab9 commit 86eab26
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions examples/label2rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def label2rgb():
label, label_names=label_names, font_size=25
)
labelviz_withname2 = imgviz.label2rgb(
label, label_names=label_names, font_size=25, loc="lt"
label, label_names=label_names, font_size=25, loc="rb"
)
img = imgviz.color.rgb2gray(rgb)
labelviz_withimg = imgviz.label2rgb(label, img=img)
Expand All @@ -38,7 +38,7 @@ def label2rgb():
plt.axis("off")

plt.subplot(133)
plt.title("loc=lt")
plt.title("loc=rb")
plt.imshow(labelviz_withname2)
plt.axis("off")

Expand Down
16 changes: 7 additions & 9 deletions imgviz/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@ def label2rgb(
if label_names is None:
return res

if loc == "centroid":
for label_i in np.unique(label):
if label_i == -1:
continue # unlabeled
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 len(unique_labels) == 0:
return res

if loc == "centroid":
for label_i in unique_labels:
mask = label == label_i
if 1.0 * mask.sum() / mask.size < thresh_suppress:
continue
Expand All @@ -138,11 +141,6 @@ def label2rgb(
font_path=font_path,
)
elif loc in ["rb", "lt"]:
unique_labels = np.unique(label)
unique_labels = unique_labels[unique_labels != -1]
if not unique_labels.size:
return res

text_sizes = np.array(
[
draw_module.text_size(
Expand Down

0 comments on commit 86eab26

Please sign in to comment.