Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
blog: show COVID detection bbox
import pydicom
from pydicom.pixel_data_handlers import apply_voi_lut
# load the DICOM file
dicom = pydicom.dcmread(dicom_path)
# extract the image bitmap
img = apply_voi_lut(dicom.pixel_array, dicom)
import matplotlib.pyplot as plt
from matplotlib import patches
fig, ax = plt.subplots()
ax_im = ax.imshow(img, cmap="gray")
bbox_property = dict(linewidth=1, edgecolor='r', facecolor='none')
for bbox in train_images["boxes"][idx_]:
xy_wh = (bbox['x'], bbox['y']), bbox['width'], bbox['height']
# Create a Rectangle patch
rect = patches.Rectangle(*xy_wh, **bbox_property)
# Add the patch to the Axes
ax.add_patch(rect)
plt.colorbar(ax_im)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment