Apply a nonlinear transform to model using Python code

Hi to everyone, on this occasion we are trying to automate a specific transform process. Our goal is to apply a transform we made before in a slicer 3D model. The workflow is the next one:

• We use the module Curved Planar Reformat to straight the volume. This procedure yields two new nodes in the Slicer Scene: The straightened volume, and the Straighten Transform.

• We want to apply this transform (which is nonlinear and non-computable in a 4x4 matrix) to a model we made before .

• We use the transformed model for own purposes.

Apply this Straightening Transform is quite easy doing the usual ‘clicks’ in Tranforms module. The problem arises when we try to automate the transforming process using Python. The typical ways to interact with modules are not capable to use Transforms module as we need.

In case the module can be used with Python code, we also need to know how to select the inverse transform who appears in the Slicer GUI and apply/unapply a transform.

Is there a way to automate the process using code?

Thanks :blush:

Pd: We check the following related link:
Apply nonlinear transform to point in python ,
but we don´t find anything useful on it.

Something like the following should work for applying a nonlinear transform to a model:

straightenTransformNode = getNode('Straighten Transform')
# Get the model node that you want to transform
modelName = 'MyModel' # change this to whatever the name of your model is
modelNode = getNode(modelName)
# To apply transform to model
# To unapply a transform

Separately, to invert a transform node, call Inverse() on it


You might also find the following discussion helpful: Invert transform (Elastix)

Thanks a lot, your post it´s so helpful and now we can apply nonlinear transforms to models.

1 Like