Hi all,
I would like to make some function which perform real-time resampling depending on the transform matrix
I used simple itk resample function, however, this one quite slow (e.g, 1~2 s for one interpolation)
Is there more effcieint way to perform the resample ?
Below, this is my cord
# Create a new transform
transformNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTransformNode", "MyTransform")
transNode.SetAndObserveTransformNodeID(transformNode.GetID())
# Callback function that will be called each time the transform is modified
def onMyTransformModified(caller, event):
transformMatrix = vtk.vtkMatrix4x4()
caller.GetMatrixTransformToWorld(transformMatrix)
transformMatrix.Invert()
matrix_arr = []
translate_arr = []
for i in range(0, 3):
for j in range(0, 3):
matrix_arr.append(transformMatrix.GetElement(i, j))
translate_arr.append(transformMatrix.GetElement(i, 3))
rigid_euler = sitk.Euler3DTransform()
rigid_euler.SetMatrix(matrix_arr) # rotate
rigid_euler.SetTranslation(translate_arr) # move to
interpolator = sitk.sitkCosineWindowedSinc
default_value = 0
resampler = sitk.ResampleImageFilter()
resampler.SetInterpolator(interpolator)
resampler.SetReferenceImage(reference_image)
resampler.SetOutputPixelType(sitk.sitkFloat32)
resampler.SetDefaultPixelValue(default_value)
resampler.SetTransform(rigid_euler)
resampler.SetNumberOfThreads(10)
resample_image = resampler.Execute(excute_image)
sitkUtils.PushVolumeToSlicer(resample_image, targetNode=transNode)
# Add an observer that will make the callback function called each time the transform is modified
observationTag = transformNode.AddObserver(slicer.vtkMRMLTransformableNode.TransformModifiedEvent, onMyTransformModified)