Tune a mask
Imperfect masks can be tuned through the addition and subtraction of pixels. SciPy includes several useful methods for accomplishing these ends. These include:
binary_dilation: Add pixels along edgesbinary_erosion: Remove pixels along edgesbinary_opening: Erode then dilate, "opening" areas near edgesbinary_closing: Dilate then erode, "filling in" holes
For this exercise, create a bone mask then tune it to include additional pixels.
For the remaining exercises, we have run the following import for you:
import scipy.ndimage as ndi
Este exercício faz parte do curso
Biomedical Image Analysis in Python
Instruções do exercício
- Create a bone by selecting pixels from
imthat are greater than or equal to145. - Use
ndi.binary_dilation()to increase the size ofmask_bone. Set the number ofiterationsto5to perform the dilation multiple times. - Use
ndi.binary_closing()to fill in holes inmask_bone. Set the number ofiterationsto5to holes up to 10 pixels wide. - Plot the original and tuned masks.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Create and tune bone mask
mask_bone = ____
mask_dilate = ndi.binary_dilation(____, ____)
mask_closed = ____
# Plot masked images
fig, axes = plt.subplots(1,3)
axes[0].imshow(mask_bone)
axes[1].imshow(mask_dilate)
____
format_and_render_plot()