# BSpline Multiresolution error while setting Transform

**URL:** https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562
**Category:** Algorithms
**Tags:** registration, bspline
**Created:** [October 22, 2020, 8:49pm UTC](https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562 "2020-10-22T20:49:42Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)
#### Post date: [October 22, 2020, 8:49pm UTC](https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562/1 "2020-10-22T20:49:42Z")

</div>

Hello, everyone.

I am writing a MULTISTAGE registration pipeline.  
1st Stage is a `3D rigid` one;  
the output is added into `CompositTransform` object;  
Then I set the `CompositTransform` as the initial transform of the Deformable BSpline stage;

Moving forward I set the multi-resolution `transformAdaptors` using the `CompositTransform` in the `transformAdaptors->SetTransform()` and it yields an ERROR: Transform mismatch.

Any clues are welcome.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 22, 2020, 9:56pm UTC](https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562/2 "2020-10-22T21:56:04Z")

</div>

I think the usual way is to add BSpline to Composite, like in [DeformableRegistration15](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Examples/RegistrationITKv4/DeformableRegistration15.cxx) which was [recently updated](https://github.com/InsightSoftwareConsortium/ITK/commit/0aba9318fbfbd5848e69cd125e3d5c91b8840643).

---

<div class="post-metadata">

### Author: ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)
#### Post date: [October 23, 2020, 3:42pm UTC](https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562/3 "2020-10-23T15:42:09Z")

</div>

Thanks for answering @dzenanz.  
I did that. I Created a `deformableTransform`, initialized that, added to the `compositTransform`,  
and set the command `compositeTransform->SetOnlyMostRecentTransformToOptimizeOn()`;

Then I set the `compositTransform` into the `deformableRegistration->SetInitialTransform()` with the extra command `registration->InPlaceOn()`;

Now, the questions that arises are the following:

Is it necessary to give the command  
`compositeTransform->AddTransform(deformableRegistration->GetModifiableTransform())` in order to have the `compositTransform` fully updated?

In the `resampling` stage, what transform should I use: the `compositTransform` or the `deformableTransform`?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 23, 2020, 4:31pm UTC](https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562/4 "2020-10-23T16:31:42Z")

</div>

> [@machadoL](#):
>
> Is it necessary to give the command  
> `compositeTransform->AddTransform(deformableRegistration->GetModifiableTransform())` in order to have the `compositTransform` fully updated?

It probably is. But you can try omitting it and see what happens.

> [@machadoL](#):
>
> In the `resampling` stage, what transform should I use: the `compositTransform` or the `deformableTransform` ?

Probably `compositTransform`.

---

<div class="post-metadata">

### Author: ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)
#### Post date: [October 30, 2020, 8:52pm UTC](https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562/5 "2020-10-30T20:52:52Z")

</div>

Hey @dzenanz.  
I tried to use the transforms as mentioned. Now I’m getting a quite random error about the metric:

```
ExceptionObject caught !

itk::ExceptionObject (0x560232884590)
Location: "unknown" 
File: /home/leo/General_sources/ITK-5.0.1/Modules/Core/Common/src/itkPoolMultiThreader.cxx
Line: 154
Description: itk::ERROR: PoolMultiThreader(0x5602328a1210): Exception occurred during SingleMethodExecute
/usr/local/include/ITK-5.0/itkImageToImageMetricv4GetValueAndDerivativeThreaderBase.hxx:260:
Exception in GetValueAndDerivativeProcessPoint:
/usr/local/include/ITK-5.0/itkBSplineBaseTransform.h:284:
itk::ERROR: BSplineTransform(0x560232885970): ComputeJacobianWithRespectToPosition not yet implemented for BSplineTransform 

```

So far, I have no clue where this error starts. Although another doubt arises:  
What’s the true difference between:

```
registration->SetInitialTransform();
registration->InPlaceOn();

```

and

`registration->SetMovingInitialTransform();`

What I am thinking is if it is correct to set:

`registration->setInitialTransform(CompositTransform)`

and

`registration->SetMovingInitialTransform(dtransform)`

to later on `GetModifiableTransform` give me the updated dtransform alone.

Any help is appreciated. Thanks.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 30, 2020, 9:24pm UTC](https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562/6 "2020-10-30T21:24:50Z")

</div>

Perhaps comments here might be of help:

> <https://github.com/InsightSoftwareConsortium/ITK/commit/4698849b1cc46a084cca374c35c1f969a8c96d30>

---

<div class="post-metadata">

### Author: ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)
#### Post date: [November 10, 2020, 8:26pm UTC](https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562/7 "2020-11-10T20:26:39Z")

</div>

Hey @dzenanz, thanks for the help. Although I did not get any further.

A better way to state my issue is:  
How can I set the **BULK transform** in a BSpline registration?  
I have the bulk transform (a rigid registration previously found) I only need to connect that into the pipeline.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 10, 2020, 9:08pm UTC](https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562/8 "2020-11-10T21:08:54Z")

</div>

There are 2 classes, [BSplineDeformableTransform](https://itk.org/Doxygen/html/classitk_1_1BSplineDeformableTransform.html) which has [SetBulkTransform()](https://itk.org/Doxygen/html/classitk_1_1BSplineDeformableTransform.html#af9a3a2e2808209988cd6412168216687) method and [BSplineTransform](https://itk.org/Doxygen/html/classitk_1_1BSplineTransform.html), which doesn’t. `BSplineTransform` is therefore usually part of composite transform. [DeformableRegistration15 example](https://github.com/InsightSoftwareConsortium/ITK/blob/v5.1.1/Examples/RegistrationITKv4/DeformableRegistration15.cxx) uses `BSplineTransform` + composite transform.

---

<div class="post-metadata">

### Author: ![machadoL](https://discourse.itk.org/user_avatar/discourse.itk.org/machadol/32/662_2.png) [@machadoL](https://discourse.itk.org/u/machadoL)
#### Post date: [November 11, 2020, 6:54pm UTC](https://discourse.itk.org/t/bspline-multiresolution-error-while-setting-transform/3562/10 "2020-11-11T18:54:29Z")

</div>

I create **[another topic](https://discourse.itk.org/t/multistage-registration-using-itkregistrationmethodv4/3608)**. I guess we can make a clearer discussion.
