Skip to content

Instantly share code, notes, and snippets.

@Borda
Last active August 19, 2021 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Borda/0c4afc86db7d273da257914ff8a03d41 to your computer and use it in GitHub Desktop.
Save Borda/0c4afc86db7d273da257914ff8a03d41 to your computer and use it in GitHub Desktop.
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