| 1 |
|
| 2 |
|
| 3 |
import matplotlib.pyplot as plt |
| 4 |
|
| 5 |
import imgviz |
| 6 |
|
| 7 |
|
| 8 |
def instances2rgb(): |
| 9 |
data = imgviz.data.voc() |
| 10 |
|
| 11 |
captions = [data["class_names"][label_id] for label_id in data["labels"]] |
| 12 |
insviz1 = imgviz.instances2rgb( |
| 13 |
image=data["rgb"], |
| 14 |
bboxes=data["bboxes"], |
| 15 |
labels=data["labels"], |
| 16 |
captions=captions, |
| 17 |
) |
| 18 |
insviz2 = imgviz.instances2rgb( |
| 19 |
image=data["rgb"], |
| 20 |
masks=data["masks"] == 1, |
| 21 |
labels=data["labels"], |
| 22 |
captions=captions, |
| 23 |
) |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
plt.figure(dpi=200) |
| 28 |
|
| 29 |
plt.subplot(131) |
| 30 |
plt.title("rgb") |
| 31 |
plt.imshow(data["rgb"]) |
| 32 |
plt.axis("off") |
| 33 |
|
| 34 |
plt.subplot(132) |
| 35 |
plt.title("instances\n(bboxes)") |
| 36 |
plt.imshow(insviz1) |
| 37 |
plt.axis("off") |
| 38 |
|
| 39 |
plt.subplot(133) |
| 40 |
plt.title("instances\n(masks)") |
| 41 |
plt.imshow(insviz2) |
| 42 |
plt.axis("off") |
| 43 |
|
| 44 |
img = imgviz.io.pyplot_to_numpy() |
| 45 |
plt.close() |
| 46 |
|
| 47 |
return img |
| 48 |
|
| 49 |
|
| 50 |
if __name__ == "__main__": |
| 51 |
from base import run_example |
| 52 |
|
| 53 |
run_example(instances2rgb) |