# [Insight-users] Small discrepancy after applying registration transform

Fri Apr 1 09:40:58 EDT 2011

```Thank you for the tip!

I found the solution if someone encounters a similar problem:

The calculation of the position vector P2 was incorrect, it should have
been:

V2 = M*(V - O).

Now it is fine.

MVH
===================================
|   Patrik Brynolfsson
|   Ph.D. student at Dept of Radiation Physics
|   Umeå University
|   SE-901 87 Umeå
|   Sweden
|   Phone: +46 (0)90 785 2296
===================================

2011/4/1 Johnson, Hans J <hans-johnson at uiowa.edu>

>  There is an insight journal article called "ResampleInPlace". That
> provides code to do this.
>
>
> On Apr 1, 2011, at 5:16 AM, "Patrik Brynolfsson" <
>
>   Hello,
>
>  I have a little problem that I think is just down to some small detail in
> my understanding of DICOM and ITK. I want avoid resampling an image when
> applying a rigid transform by applying the transform to the directional
> cosines (C) and the position vector (V) of the image instead. I do this by
> first getting the rotation matrix (M) and the offset (O) from the transform
> (an Euler3DTransform) and setting the new directional cosines as the matrix
> multiplication of the rotation matrix and the directional cosines,
>
>  C2=M*C,
>
>  and the new position vector as
>
>  V2 = M*V + O.
>
>  I noticed that in order to get correct results I must subtract the offset
> O, so
>
>  V2 = M*V - O.
>
>  I check the result by resampling my new image using an identity transform
> and my fixed image as reference and then take the difference between them.
> The result is slightly worse than if I just resample my original moving
> image with the resulting transform of the registration. I use bsplines  = 3
> when resampling in both cases. It seems that my way of applying the
> transform is off by a voxel or so.
>
>  What am I doing wrong? Since I wanted to add the offset instead of
> subtracting it I guess I don't fully understand the parameters I'm working
> with so I guess I'm making more mistakes. Can someone point them out to me?
> Maybe there is already a filter that does what I want to do?
>
>
>  Regards
> ===================================
> |   Patrik Brynolfsson
> |   Ph.D. student at Dept of Radiation Physics
> |   Umeå University
> |   SE-901 87 Umeå
>  |   Sweden
> |   Phone: +46 (0)90 785 2296
>  ===================================
>
>   _____________________________________
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> http://www.itk.org/mailman/listinfo/insight-users
>
>
>
> ------------------------------
> Notice: This UI Health Care e-mail (including attachments) is covered by
> the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is
> confidential and may be legally privileged.  If you are not the intended
> recipient, you are hereby notified that any retention, dissemination,
> distribution, or copying of this communication is strictly prohibited.
> delete it.  Thank you.
> ------------------------------
>
> _____________________________________
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>