# Show transform being updated during registration

**URL:** https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507
**Category:** Development
**Tags:** registration
**Created:** [November 30, 2022, 12:43pm UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507 "2022-11-30T12:43:51Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)
#### Post date: [November 30, 2022, 12:43pm UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/1 "2022-11-30T12:43:51Z")

</div>

hi community  
can i set a callback function to brainsfit or elastix when brainsfit or elastix running on each iteration?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 1, 2022, 1:48am UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/3 "2022-12-01T01:48:12Z")

</div>

Brainsfit is a CLI module. [CLI module output is collected during execution](https://vtkSlicerCLIModuleLogic.cxx) and made accessible when execution ends. If the process output contains specially formatted “progress output” text (information about what stage the processing is in and what is the progress within that stage and what is the overall progress) then that information is displayed during execution in the module GUI. However, I don’t think Brainsfit module provides progress output. You would need to modify it to gather progress input during execution and print it on the process output with that special formatting.

Elastix is a Python scripted module. You can change the part of the Python script that displays the process output in the Python console to print it in a GUI widget or interpret it and use it any way you want (display it as a progress bar, show current metric value, etc.).

What is your overall goal? Would you like to display progress information during registration?

---

<div class="post-metadata">

### Author: ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)
#### Post date: [December 2, 2022, 2:49am UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/4 "2022-12-02T02:49:27Z")

</div>

thank you very much lassoan  
your advice is very helpful , i think i know what to do in next step  
yes,my boss want to display registration moving image in each iteration step , he says “it’s owesome to show registration progress on renderwindow when the registration button is pressed”

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 2, 2022, 3:50pm UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/5 "2022-12-02T15:50:57Z")

</div>

I see. Yes, the videos showing the evolution of the registration in time are very cool. During time when you start experimenting with new registration tools it may be actually useful to see this, because you could abort the registration if you see that it is not converging at all.

However, during normal the disadvantage of slowdown (caused by exporting the transformation parameters, applying them, and update the rendering) could be significant, and there would be not much advantage in seeing the evolving transformation.

Implementation for linear transforms could be relatively easy, but it would require some changes in the registration tool (to display transform parameters), a small changes in Slicer core to continuously make the process output available (not just when the registration is finished), and development of a small script that observes the process output and updates the transform in the scene. For warping transforms, passing the transform parameters and applying the transform could be time-consuming, so it could significantly slow down the registration, therefore probably the feature would be very rarely used.

Still, if you are interested in developing this then we can guide you through the process.

---

<div class="post-metadata">

### Author: ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)
#### Post date: [December 5, 2022, 3:13am UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/6 "2022-12-05T03:13:58Z")

</div>

thank you very much lassoan  
thank you for reply so detail  
Our use scenario is to register images of different modal of the same patient, so rigid registration is most often used, which is also the reason why similar manufacturers use video to show the registration process  
i am interested in developing this,I hope I can get your guidance !

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 5, 2022, 1:00pm UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/7 "2022-12-05T13:00:04Z")

</div>

The first step is to update the CLI module execution class to save process output into the CLI node during execution (not just at the end, when execution is completed). For this you need to [build Slicer](https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/index.html). Let us know if you have managed to build Slicer or you have run into errors that you cannot solve.

---

<div class="post-metadata">

### Author: ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)
#### Post date: [December 6, 2022, 2:19am UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/8 "2022-12-06T02:19:50Z")

</div>

thank you lassoan  
i have managed to build Slicer and understand the code of main module in Slicer  
i am trying to start to update the CLI module and wait for the second step 😄

---

<div class="post-metadata">

### Author: ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)
#### Post date: [December 6, 2022, 5:04pm UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/9 "2022-12-06T17:04:00Z")

</div>

> [@jay1987](#):
>
> i have managed to build Slicer and understand the code of main module in Slicer

👍

> [@jay1987](#):
>
> the second step

You may want to use the debugger to go through the code in `vtkSlicerCLIModuleLogic.cxx` in [this directory](https://github.com/Slicer/Slicer/blob/main/Base/QTCLI) to see how progress is handled. I believe Andras is suggesting that you can extend the progress notification code to include a matrix that would update the transform for a real-time update.

---

<div class="post-metadata">

### Author: ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)
#### Post date: [December 7, 2022, 12:58am UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/10 "2022-12-07T00:58:11Z")

</div>

thank you pieper!  
your suggestion is very detail i think i understand what to do next now

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [December 7, 2022, 9:52pm UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/11 "2022-12-07T21:52:01Z")

</div>

Congratulations @jay1987, successfully building Slicer is already an accomplishment.

I’ve made an improvement in Slicer core ([pull request](https://github.com/Slicer/Slicer/pull/6721) is expected to be integrated tonight), which allows continuously monitoring process output. This allows getting transforms from BRAINS and ANTs registration (Elastix output can be captured [here](https://github.com/lassoan/SlicerElastix/blob/c2e33b8aba51b877bc7e8765ac52f82692c39223/Elastix/Elastix.py#L708)).

Now, the next step is to check if the registration tool that you want to use has an option to print the current rigid transform parameters on its output. If you cannot find such option, then ask on the forum/support site of the tool to confirm that the tool cannot print the transform parameters and ask advice on how to implement it.

Once you have the transform parameters on the output then you can add a simple scripted module that observes the output of BRAIN, ANTs, or Elastix output and updates a transform node accordingly.

---

<div class="post-metadata">

### Author: ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)
#### Post date: [December 8, 2022, 1:56am UTC](https://discourse.slicer.org/t/show-transform-being-updated-during-registration/26507/12 "2022-12-08T01:56:58Z")

</div>

thank you lassoan !  
thank you for made such work for the question .  
i think i can find the way to print the rigid transform parameters on the output  
I need some time to complete this function with your help, and then I will share this script for everyone to use.
