Get Started

Interpolation

Interpolation is how new pixel intensities are estimated when an image transformation is applied. It is implemented in SciPy using sets of spline functions.

Editing the interpolation order when using a function such as ndi.zoom() modifies the resulting estimate: higher orders provide more flexible estimates but take longer to compute.

For this exercise, upsample im and investigate the effect of different interpolation orders on the resulting image.

This is a part of the course

“Biomedical Image Analysis in Python”

View Course

Exercise instructions

  • Use ndi.zoom() to upsample im from a shape of 128, 128 to 512, 512 twice. First, use an interpolation order of 0, then set order to 5.
  • Print the array shapes of im and up0.
  • Plot close-ups of the images. Use the index range 128:256 along each axis.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Upsample "im" by a factor of 4
up0 = ndi.zoom(____, zoom=____, order=____)
up5 = ____

# Print original and new shape
print('Original shape:', ____)
print('Upsampled shape:', ____)

# Plot close-ups of the new images
fig, axes = plt.subplots(1, 2)
axes[0].imshow(up0[128:256, 128:256])
axes[1].imshow(____)
format_and_render_plots()

This exercise is part of the course

Biomedical Image Analysis in Python

IntermediateSkill Level
4.6+
12 reviews

Learn the fundamentals of exploring, manipulating, and measuring biomedical image data.

For the final chapter, you'll need to use your brain... and hundreds of others! Drawing data from more than 400 open-access MR images, you'll learn the basics of registration, resampling, and image comparison. Then, you'll use the extracted measurements to evaluate the effect of Alzheimer's Disease on brain structure.

Exercise 1: Spatial transformationsExercise 2: TranslationsExercise 3: RotationsExercise 4: Affine transformExercise 5: Resampling and interpolationExercise 6: ResamplingExercise 7: Interpolation
Exercise 8: Comparing imagesExercise 9: Mean absolute errorExercise 10: Intersection of the unionExercise 11: Normalizing measurementsExercise 12: Identifying potential confoundsExercise 13: Testing group differencesExercise 14: Normalizing metrics

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free