| 1 |
|
| 2 |
|
| 3 |
import matplotlib.pyplot as plt |
| 4 |
|
| 5 |
import imgviz |
| 6 |
|
| 7 |
|
| 8 |
def label2rgb(): |
| 9 |
data = imgviz.data.voc() |
| 10 |
|
| 11 |
rgb = data["rgb"] |
| 12 |
label = data["class_label"] |
| 13 |
|
| 14 |
label_names = ["{}:{}".format(i, n) for i, n in enumerate(data["class_names"])] |
| 15 |
labelviz_withname1 = imgviz.label2rgb( |
| 16 |
label, label_names=label_names, font_size=25, loc="centroid" |
| 17 |
) |
| 18 |
labelviz_withname2 = imgviz.label2rgb( |
| 19 |
label, label_names=label_names, font_size=25, loc="rb" |
| 20 |
) |
| 21 |
img = imgviz.color.rgb2gray(rgb) |
| 22 |
labelviz_withimg = imgviz.label2rgb(label=label, image=img) |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
plt.figure(dpi=200) |
| 27 |
|
| 28 |
plt.subplot(131) |
| 29 |
plt.title("+img") |
| 30 |
plt.imshow(labelviz_withimg) |
| 31 |
plt.axis("off") |
| 32 |
|
| 33 |
plt.subplot(132) |
| 34 |
plt.title("loc=centroid") |
| 35 |
plt.imshow(labelviz_withname1) |
| 36 |
plt.axis("off") |
| 37 |
|
| 38 |
plt.subplot(133) |
| 39 |
plt.title("loc=rb") |
| 40 |
plt.imshow(labelviz_withname2) |
| 41 |
plt.axis("off") |
| 42 |
|
| 43 |
img = imgviz.io.pyplot_to_numpy() |
| 44 |
plt.close() |
| 45 |
|
| 46 |
return img |
| 47 |
|
| 48 |
|
| 49 |
if __name__ == "__main__": |
| 50 |
from base import run_example |
| 51 |
|
| 52 |
run_example(label2rgb) |