微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用仿射变换进行翻转时,简单的itk行为不符合预期

如何解决使用仿射变换进行翻转时,简单的itk行为不符合预期

我想使用simpleitk翻转音量。

vol = np.arange(1,25).reshape((4,6))
print(vol)
vol = sitk.GetimageFromArray(vol)

结果:

[[ 1  2  3  4  5  6]
 [ 7  8  9 10 11 12]
 [13 14 15 16 17 18]
 [19 20 21 22 23 24]]

根据this torurial,有两种实现方法

  1. 使用切片
  2. 使用仿射变换。

但是,由于变换中心,第二种方法的结果不正确。

flip = sitk.AffineTransform(2) 
flip.SetMatrix([1.0,-1.0]) volume_shape= np.array(vol.GetSize()) 
center = (int(volume_shape[0] / 2),int(volume_shape[1] / 2))
#if I change the center to (3,1.5) it works 
flip.SetCenter(center)
interp_img = sitk.sitkLinear 
vol_resampled = sitk.Resample(vol,flip,interp_img,0.0)

print(sitk.GetArrayFromImage(vol_resampled))
print(sitk.GetArrayFromImage(vol[:,::-1]))

结果:

[[ 0  0  0  0  0  0]
 [19 20 21 22 23 24]
 [13 14 15 16 17 18]
 [ 7  8  9 10 11 12]]

[[19 20 21 22 23 24]
 [13 14 15 16 17 18]
 [ 7  8  9 10 11 12]
 [ 1  2  3  4  5  6]]

如果有人能解释原因,我将不胜感激。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。