開始使用免費開始

重取樣(Resampling)

影像可能以各種不同的形狀與尺寸取得。當需要讓這些形狀一致時,重取樣 就很實用。兩個常見應用是:

  • 降取樣(Downsampling):合併像素資料以「減少」尺寸
  • 升取樣(Upsampling):分配像素資料以「增加」尺寸

在本練習中,先對腦部影像(im)做幾何轉換,再進行重取樣,觀察對影像形狀的影響。

本練習屬於課程

Python 的生醫影像分析

檢視課程

練習說明

  • im 向左與向上各平移 20 個像素,即 (-20, -20)。接著,向下旋轉 35 度。記得為 reshape 指定值。
  • 使用 ndi.zoom() 將影像從 (256, 256) 降取樣到 (64, 64)。
  • 使用 ndi.zoom() 將影像從 (256, 256) 升取樣到 (1024, 1024)。
  • 繪製重取樣後的影像。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Center and level image
xfm = ndi.shift(____, shift=____)
xfm = ndi.rotate(____, angle=____, reshape=____)

# Resample image
im_dn = ndi.zoom(xfm, zoom=____)
im_up = ____

# Plot the images
fig, axes = plt.subplots(2, 1)
axes[0].imshow(im_dn)
____
format_and_render_plot()
編輯並執行程式碼