开始使用免费开始使用

插值

当对图像进行变换时,插值 用于估计新像素的强度。SciPy 通过样条函数集合来实现这一点。

在使用 ndi.zoom() 等函数时,调整插值 order 会改变估计结果:阶数越高,估计越灵活,但计算时间也越长。

本练习中,请对 im 进行上采样,并观察不同插值阶数对结果图像的影响。

本练习是课程的一部分

Python 中的生物医学图像分析

查看课程

练习说明

  • 使用 ndi.zoom()im 的形状从 128, 128 上采样到 512, 512,重复两次:第一次使用插值 order 为 0,第二次将 order 设为 5。
  • 打印 imup0 的数组形状。
  • 绘制图像的局部放大图。沿每个轴使用索引范围 128:256

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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()
编辑并运行代码