LoslegenKostenlos loslegen

Select objects

Labels are like object "handles" - they give you a way to pick up whole sets of pixels at a time. To select a particular object:

  1. Find the label value associated with the object.
  2. Create a mask of matching pixels.

For this exercise, create a labeled array from the provided mask. Then, find the label value for the centrally-located left ventricle, and create a mask for it.

Diese Übung ist Teil des Kurses

Biomedical Image Analysis in Python

Kurs anzeigen

Anleitung zur Übung

  • Use ndi.label() to assign labels to each separate object in mask.
  • Find the index value for the left ventricle label by checking the center pixel (128, 128).
  • Create a mask of pixels matching the left ventricle label. Using np.where, set pixels labeled as lv_val to 1 and other values to np.nan.
  • Use plt.imshow() to overlay the selected label on the current plot.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Label the image "mask"
labels, nlabels = ____

# Select left ventricle pixels
lv_val = ____[128, 128]
lv_mask = ____

# Overlay selected label
plt.imshow(____, cmap='rainbow')
plt.show()
Code bearbeiten und ausführen