Hi,
I am trying to split the dvf into two dvfs and apply in order.
However the result of deforming with one dvf is not the same as deforming with the split two dvfs.
I am wondering why is happen and how to fix it.
here is my code:
def deform_img(img,dvf):
resampler = sitk.ResampleImageFilter() resampler.SetReferenceImage(img) dis_tx = sitk.DisplacementFieldTransform(sitk.Cast(dvf, sitk.sitkVectorFloat64)) resampler.SetTransform(dis_tx) new_rigid_post = resampler.Execute(img) return new_rigid_post
def test10():
post = np.zeros((128, 256, 256)) post[40:90, 40:90, 40:90] = 255 itk_post = sitk.GetImageFromArray(post) pre = np.zeros((128, 256, 256)) pre[30:80, 20:70, 10:60] = 255 itk_pre = sitk.GetImageFromArray(pre) dvf = np.zeros((128, 256, 256, 3)) dvf[:, :, :, 0] = 30.2 dvf[:, :, :, 1] = 20.2 dvf[:, :, :, 2] = 10.2 itk_dvf = sitk.GetImageFromArray(dvf) new_post=deform_img(itk_post,itk_dvf) new_post_img = sitk.GetArrayFromImage(new_post) dvf1 = np.zeros((128, 256, 256, 3)) dvf1[:, :, :, 0] = 20.0 dvf1[:, :, :, 1] = 15.0 dvf1[:, :, :, 2] = 5.0 itk_dvf1 = sitk.GetImageFromArray(dvf1) part1_post = deform_img(itk_post, itk_dvf1) dvf2 = np.zeros((128, 256, 256, 3)) dvf2[:, :, :, 0] = 10.2 dvf2[:, :, :, 1] = 5.2 dvf2[:, :, :, 2] = 5.2 itk_dvf2 = sitk.GetImageFromArray(dvf2) part2_post = deform_img(part1_post, itk_dvf2) part2_post_img = sitk.GetArrayFromImage(part2_post) print(np.array_equal(new_post_img,part2_post_img))
The print(np.array_equal(new_post_img,part2_post_img)) returns false.