開始使用免費開始

內插法

「內插法(interpolation)」是在套用影像轉換時,用來估計新像素強度的方法。在 SciPy 中以一組樣條(spline)函式實作。

在使用 ndi.zoom() 等函式時,調整內插的 order 會改變估計結果:較高的階數能提供更彈性的估計,但計算時間也會更久。

在本練習中,請將 im 上採樣(upsample),並觀察不同內插階數對輸出影像的影響。

本練習屬於課程

Python 的生醫影像分析

檢視課程

練習說明

  • 使用 ndi.zoom() 兩次將 im128, 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()
編輯並執行程式碼