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.
This exercise is part of the course
Biomedical Image Analysis in Python
Exercise instructions
- 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.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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()