內插法
「內插法(interpolation)」是在套用影像轉換時,用來估計新像素強度的方法。在 SciPy 中以一組樣條(spline)函式實作。
在使用 ndi.zoom() 等函式時,調整內插的 order 會改變估計結果:較高的階數能提供更彈性的估計,但計算時間也會更久。
在本練習中,請將 im 上採樣(upsample),並觀察不同內插階數對輸出影像的影響。
本練習屬於課程
Python 的生醫影像分析
練習說明
- 使用
ndi.zoom()兩次將im從128, 128上採樣到512, 512。第一次使用內插order為 0,接著將order設為 5。 - 列印
im與up0的陣列形狀。 - 繪製影像的局部放大圖。沿每個軸使用索引範圍
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()