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

2024-06-17 13:24:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用SimpleTk翻转一个卷

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,0,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]]

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


Tags: 方法imgnpintcenterprintshapevolume