開始使用免費開始

旋轉

當物體傾斜或翻轉時,可以旋轉影像。使用 ndi.rotate() 時,影像會以中心為基準,依你指定的角度,從右側的水平軸開始計算旋轉。

在這個練習中,請平移並旋轉腦部影像(im),讓它大致保持水平,並「面向」影像的右側。

本練習屬於課程

Python 的生醫影像分析

檢視課程

練習說明

  • im 平移至較中心的位置:向左 20 個像素、向上 20 個像素。
  • 使用 ndi.rotatexfm 旋轉 30 度朝下。設定 reshape=False 以避免影像形狀改變。
  • 繪製原始影像與變換後的影像。

動手互動練習

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

# Shift the image towards the center
xfm = ____

# Rotate the shifted image
xfm = ndi.rotate(____, angle=____, reshape=____)

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