| import matplotlib.pyplot as plt |
| from skimage import io |
| from skimage.draw import rectangle_perimeter |
| from skimage.color import label2rgb |
|
|
| def display_bounding_boxes(image_path, boxes, labels): |
| |
| image = io.imread(image_path) |
|
|
| |
| if image.ndim == 2: |
| image = label2rgb(image) |
|
|
| |
| plt.imshow(image) |
|
|
| |
| for box, label in zip(boxes, labels): |
| ymin, xmin, ymax, xmax = box |
| rr, cc = rectangle_perimeter(start=(ymin, xmin), end=(ymax, xmax), shape=image.shape) |
| image[rr, cc] = (0, 1, 0) |
|
|
| |
| plt.text(xmin, ymin - 2, label, color='r') |
|
|
| plt.axis('off') |
| plt.show() |
|
|