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:
- Find the label value associated with the object.
- 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
Anleitung zur Übung
- Use
ndi.label()
to assign labels to each separate object inmask
. - 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 aslv_val
to1
and other values tonp.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()