Exercise

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 edges
  • binary_erosion: Remove pixels along edges
  • binary_opening: Erode then dilate, "opening" areas near edges
  • binary_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

Instructions

100 XP
  • Create a bone by selecting pixels from im that are greater than or equal to 145.
  • Use ndi.binary_dilation() to increase the size of mask_bone. Set the number of iterations to 5 to perform the dilation multiple times.
  • Use ndi.binary_closing() to fill in holes in mask_bone. Set the number of iterations to 5 to holes up to 10 pixels wide.
  • Plot the original and tuned masks.