开始使用免费开始使用

旋转

当目标存在倾斜或翻转时,可以对图像进行旋转。使用 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()
编辑并运行代码