bbox_det / display_BB.py
jkushwaha's picture
Update display_BB.py
5bd0afd verified
raw
history blame contribute delete
771 Bytes
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):
# Load the image
image = io.imread(image_path)
# Convert to RGB (if grayscale)
if image.ndim == 2:
image = label2rgb(image)
# Plot the image
plt.imshow(image)
# Add bounding boxes and labels
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) # Draw green bounding boxes
# Add label text
plt.text(xmin, ymin - 2, label, color='r')
plt.axis('off')
plt.show()