Hi,
I am trying to replicate the behavior of the Resample module directly on numpy arrays, because I have a separate service that cannot integrate or call slicer directly unfortunately.
This is the basic operation I would like to replicate:
vol2 = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode", vol.GetName() + "_resampled")
params = {
"inputVolume": vol.GetID(),
"outputVolume": vol2.GetID(),
"interpolationType": "nn", #nearest neighbor
"transformationFile": tr.GetID(),
"inverseITKTransformation": False,
"referenceVolume": ct.GetID(),
}
resample = slicer.cli.run(slicer.modules.resamplescalarvectordwivolume, parameters=params, wait_for_completion=True)
if resample.GetStatusString() != "Completed":
raise Exception("Resample failed")
I am trying to basically get the equivalent of the tranform 4x4 matrix but to be applied on the underlying array (ijk or jki). I am definetely doing something wrong.
This is how i thought it would work:
tr_np = slicer.util.arrayFromVTKMatrix(tr.GetMatrixTransformToParent())
# apply rasToIjk transform to the transform
ras_to_ijk = vtk.vtkMatrix4x4()
vol.GetRASToIJKMatrix(ras_to_ijk)
ras_to_ijk_np = slicer.util.arrayFromVTKMatrix(ras_to_ijk)
tr_np = np.matmul(tr_np, ras_to_ijk_np)
The results are totally off though, so I think I am missing something critical.
the general question is: how do you transform a transformMatrix to the ijk or kji coordinate system?