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

Exercise

Slice 3D images

The simplest way to plot 3D and 4D images by slicing them into many 2D frames. Plotting many slices sequentially can create a "fly-through" effect that helps you understand the image as a whole.

To select a 2D frame, pick a frame for the first axis and select all data from the remaining two: vol[0, :, :]

For this exercise, use for loop to plot every 40th slice of vol on a separate subplot. matplotlib.pyplot (as plt) has been imported for you.

Instructions

100 XP
  • Using plt.subplots(), initialize a subplots grid with 1 row and 4 columns.
  • Plot every 40th slice of vol in grayscale. To get the appropriate index, multiply ii by 40.
  • Turn off the ticks, labels, and frame for each subplot.
  • Render the figure.