# animation with bspline registration

**URL:** https://discourse.itk.org/t/animation-with-bspline-registration/915
**Category:** Beginner Questions
**Tags:** registration, python
**Created:** [May 9, 2018, 6:19pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915 "2018-05-09T18:19:28Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![henrisco82](https://discourse.itk.org/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@henrisco82](https://discourse.itk.org/u/henrisco82)
#### Post date: [May 9, 2018, 6:19pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/1 "2018-05-09T18:19:28Z")

</div>

Please I would like to make an animation suitable in gif format to see the different stages the registration does.  
I am using the example from here [http://simpleitk.readthedocs.io/en/master/Examples/ImageRegistrationMethodBSpline2/Documentation.html](http://simpleitk.readthedocs.io/en/master/Examples/ImageRegistrationMethodBSpline2/Documentation.html)  
please how can I do this?

Thank you

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [May 9, 2018, 6:26pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/2 "2018-05-09T18:26:14Z")

</div>

We have done something similar for the SimpleITK notebooks:

> **[InsightSoftwareConsortium/SimpleITK-Notebooks](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks)**
>
> Jupyter notebooks for learning how to use SimpleITK - InsightSoftwareConsortium/SimpleITK-Notebooks

You can find the script that was used to generate it here:

> <https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Utilities/intro_animation.py>

You should be able to adapt is to your particular registration method easily enough.

---

<div class="post-metadata">

### Author: ![henrisco82](https://discourse.itk.org/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@henrisco82](https://discourse.itk.org/u/henrisco82)
#### Post date: [May 9, 2018, 9:39pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/3 "2018-05-09T21:39:25Z")

</div>

[sitk\_reg\_bspline1.py](https://discourse.itk.org/uploads/default/original/1X/46c24ef6ccef394000a0da6e9dd7640c7e63aad2.py) (6.6 KB)

---

<div class="post-metadata">

### Author: ![henrisco82](https://discourse.itk.org/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@henrisco82](https://discourse.itk.org/u/henrisco82)
#### Post date: [May 9, 2018, 10:05pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/4 "2018-05-09T22:05:27Z")

</div>

please I still get some errors  
RuntimeError: Exception thrown in SimpleITK ImageRegistrationMethod\_Execute: C:\d\VS14-Win64-pkg\SimpleITK\Wrapping\Python\sitkPyCommand.cxx:135:  
sitk::ERROR: There was an error executing the Python Callable.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [May 9, 2018, 10:10pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/5 "2018-05-09T22:10:44Z")

</div>

You will need to add try-except inside you Python callable used in the events to get the error encountered. It may even be a syntax error the callables can be skittle tricky to debug and get right.

---

<div class="post-metadata">

### Author: ![henrisco82](https://discourse.itk.org/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@henrisco82](https://discourse.itk.org/u/henrisco82)
#### Post date: [May 10, 2018, 7:38am UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/6 "2018-05-10T07:38:00Z")

</div>

The error is with the save\_plot function. It says tuple index out of range. Please any ideas on how I can fix this?

```
central_index = round((f.GetSize())[2] / 2)

```

IndexError: tuple index out of range

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [May 10, 2018, 1:31pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/7 "2018-05-10T13:31:08Z")

</div>

Perhaps `len(f)` is only 2?

I have not looked closely at your script ( or the original for a while), maybe your image is a different dimension that what is expected?

---

<div class="post-metadata">

### Author: ![henrisco82](https://discourse.itk.org/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@henrisco82](https://discourse.itk.org/u/henrisco82)
#### Post date: [May 10, 2018, 2:00pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/8 "2018-05-10T14:00:34Z")

</div>

The files used in the example has .mha extension like training\_001\_mr\_T1.mha but I am testing with .png files.  
Do you think this is the problem?

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [May 10, 2018, 2:12pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/9 "2018-05-10T14:12:59Z")

</div>

Have you inspect the original image and your images? Do you know their dimensions, sizes, pixel types?

---

<div class="post-metadata">

### Author: ![henrisco82](https://discourse.itk.org/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@henrisco82](https://discourse.itk.org/u/henrisco82)
#### Post date: [May 10, 2018, 3:03pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/10 "2018-05-10T15:03:29Z")

</div>

The size of my image is 256 by 256 and it is a gray scale image

---

<div class="post-metadata">

### Author: ![henrisco82](https://discourse.itk.org/letter_avatar_proxy/v4/letter/h/41988e/32.png) [@henrisco82](https://discourse.itk.org/u/henrisco82)
#### Post date: [May 10, 2018, 3:59pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/11 "2018-05-10T15:59:08Z")

</div>

yeah that is the problem. The test image has width, height and color values, but my image just have width and height. Is there a way I can make it work without the color values?

Thanks

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [May 10, 2018, 4:20pm UTC](https://discourse.itk.org/t/animation-with-bspline-registration/915/12 "2018-05-10T16:20:12Z")

</div>

@henrisco82 ,  
The original script dealt with 3D scalar images, no color values. The blended slices are combined and converted to color by repeating the scalar value in all channels (see the line saying "convert grayscale image to color (r,g,b)). As you are working in 2D you will have to modify the code to deal with it (e.g. you don’t need all of the slice extraction, see references to central\_index in the script).

The need for using color is because we wanted the similarity metric graph to be in color, so the alpha blended grayscale extracted slices were also converted to color.

```
 hope this clarifies things
         Ziv
```
