I created a workspace that registers two files and now I want to export the computed transformation, so that I can use it outside of ImFusion.
How can I do that?
I created a workspace that registers two files and now I want to export the computed transformation, so that I can use it outside of ImFusion.
How can I do that?
Hi Fryderyk,
One possibility would be to do it via a Python script:
import imfusion as imf
img1 = imf.app.dataModel()[0] # get the first image
img2 = imf.app.dataModel()[1] # get the second image
print(img2.matrix()) # get the matrix of the second image
# ... save it to a file
Make sure the Python environment is properly setup in the Settings, and then put the code above in a .py script that you can run from the Suite (Import > Python Script) or from a workspace file:
<property name="Python Script">
<param name="location">/path/save_matrix.py</param>
<param name="execute">1</param>
<param name="inputUids"/>
<param name="outputUids"/>
</property>
Thanks!
Two follow up questions:
img2.matrix()
would give me the matrix of the second image, but I’m interested in the computed transformation. I guess I could get it by applying the inverse of img2.matrix()
from before the registration to the img2.matrix()
from after the registration. Would there be a more direct way?
I hoped that I could do this in the workspace file, because I wanted to batch it to register multiple pairs of files. How could I do that?
The idea is to add this Python script to the workspace itself, so that you can still batch it from the Suite.
In your workspace file, there is probably an entry like this in the Algorithms
section:
<property name="Image Registration">
...
</property>
You could :
(1) either run a Python script before and after the algorithm:
<property name="Python Script">
<param name="location">/path/save_matrix_before.py</param>
<param name="execute">1</param>
<param name="inputUids"/>
<param name="outputUids"/>
</property>
<property name="Image Registration">
...
</property>
<property name="Python Script">
<param name="location">/path/save_matrix_after.py</param>
<param name="execute">1</param>
<param name="inputUids"/>
<param name="outputUids"/>
</property>
(2) or duplicate the data before registering it so that both versions are available to your Python script (which would take the two matrices and multiply the inverse of the first one by the second one)