1. Learn
  2. /
  3. Courses
  4. /
  5. Biomedical Image Analysis in Python

Exercise

Segment the heart

In this chapter, we'll work with magnetic resonance (MR) imaging data from the Sunnybrook Cardiac Dataset. The full image is a 3D time series spanning a single heartbeat. These data are used by radiologists to measure the ejection fraction: the proportion of blood ejected from the left ventricle during each stroke.

To begin, segment the left ventricle from a single slice of the volume (im). First, you'll filter and mask the image; then you'll label each object with ndi.label().

This chapter's exercises have the following imports:

import imageio
import numpy as np
import scipy.ndimage as ndi
import matplotlib.pyplot as plt

Instructions 1/2

undefined XP
    1
    2
  • Apply a median filter to im. Set the size to 3.
  • Create a mask of values greater than 60, then use ndi.binary_closing() to fill small holes in it.
  • Extract a labeled array and the number of labels using ndi.label().