[Insight-users] Centered Affine Transform

Luis Ibanez luis.ibanez at kitware.com
Tue Jul 20 12:39:42 EDT 2004


Hi Lucas,

If you want to describe textually the action of the
CenteredAffineTransform, the operations are equivalent to:


1) Apply a translation in order to set the origin of
    coordinates on top of the Center of Rotation.

2) Apply the Rotation matrix ( strictly speaking in an
    Affine transform the matrix can also do scaling and
    shearing...).

3) Apply a translation to return the origin of coordinates
    to its location before step (1)

4) Apply a translation as defined in the SetTranslation
    setting of the transform.


As you can see, the transform First applies a rotation
around your specified center of rotation, and then
applies the translation.

Very often the confusion is the result of using non-formal
language in order to refer to the transforms. For example,
it is common to say "rotate the object, or translate the
object". In practice transform are mostly dealing with
the reference coordinates rather than the objects themselves.

Note that the code in the PCAShapeSignedDistanceFunction
uses the transform in the Evaluate(point) method. An incoming
point is mapped by the transform into the space of the image.

Since the operations are applied to the point, not to the image,
when you use Evalute() in order to sample the distances from a
distance map, the operations on the point are done in order :

        Rotation followed by Translation

The image "seems" to have been subject to the INVERSE of that
transform, which will be :

        Translation followed by Rotation




PLEASE READ the recomended section on the Software Guide,
this is certainly an effective treatment for "CRSCS".

The common mistake with this issue is to believe that it
is trivial, and that you don't need to read the manual to
understand what is going on.        :-)





   Regards,



     Luis






---------------
lucas wrote:

> Hi Luis,
> 
> thank you for your diagnostic. This syndrome is killing the few neurons 
> I still have alive.
> 
>> 1) Are you representing your object as a region in an image ?
> 
> I'm seting this transform as the one for a 
> PCAShapeSignedDistanceFunction and this last class is the one 
> representing the object.
> Before I was using translation and it worked fine.
> 
>>
>> 2) Are you applying a transform to this object by resampling
>>    the image using the itkResampleImageFilter, connecting
>>    the CenteredAffineTransform and extracting the output image ?
> 
> 
> No
> 
>>
>> 3) Are you often under the impresion that objects in the
>>    image move in the oposite direction to what you expect ?
> 
> My impresion is that the object is been translated first and the rotated 
> with respect to the center of rotation.
> 
>>
>> The most effective treatment against "CRSCS" is the
>> following procedure:
>>
>> 1) Find a quite place, away from any source of distraction.
>>
>> 2) Ingest a moderate amount of coffee.
>>
>> 3) Read from the ITK Software Guide the following section
>>
>>    Chapter 6, Section 6.7 "Geometric Transformation"
>>    pdf-pages 199-218.
>>
>> 4) Perform the excercises in this section. The source
>>    code will be found in  the directory
>>
>>          Insight/Examples/Filtering
>>
>>
>>
>>
>> Please let us know if you have further questions,
>>
>>
>>
>>    Thanks
>>
>>
>>
>>       Luis
>>
>>
> 
> Thanks lot Luis for your help and your good sense of humour,
> 
> Lucas
> 
> 
> 
>>
>> ----------------------
>> Lucas Lorenzo wrote:
>>
>>> Hi Luis,
>>>
>>>>
>>>> Hi Lucas,
>>>>
>>>> Please post numbers  :-)
>>>
>>>
>>>
>>> My original object is center is located at point (175 mm ; 168 mm). 
>>> So that's the center of rotation.
>>>
>>>>
>>> a) For translation I'm using (43.54 mm , -17.81 mm). If for rotation 
>>> I use a matrix [1 0 ; 0 1] then the result is as I expect: the object 
>>> is only translated and the new object center is now at (134.77 mm ; 
>>> 188.20 mm). Please, take into account that my object has an irregular 
>>> shape so the coordinates aren't 100 % precise. But this results don't 
>>> match the equation you've posted bellow. Let's do it for the new x 
>>> coordinate of the center:
>>>
>>>     x' = 1 * (x - Cx) + (Tx + Cx) = 1 * (43.54 - 43.54) + (175 + 
>>> 43.54) = 218.54 mm
>>>
>>> where Cx is the original x coordinate for the center and Tx is the x 
>>> component of the translation vector.
>>>
>>> b) If instead of using the translation vector specified before I use 
>>> its negative (- 43.54 mm , 17.81 mm) then the equation makes sense, 
>>> but now the results are not what I expect. Now the new center is 
>>> 218.54 mm instead of 131.46 mm.
>>>
>>> c) if for rotation I use a matrix [0 -1 ; 1 0] (we are rotating the 
>>> image 90 degrees) around center (174.765 mm, 175.242 mm) and I use a 
>>> translation vector of (43.5537 mm, -17.8095 mm), then the object is 
>>> rotated according to what I expect but the new center is translated 
>>> to location (218.54 mm , 152 mm).
>>> If I apply the equations then the new center will be at (218.3187 mm 
>>> , 157.4325 mm).
>>>
>>> d) if for rotation I use a matrix [0 -1 ; 1 0] (we are rotating the 
>>> image 90 degrees) around center  (183.42 mm, 176.236 mm) and I use a 
>>> translation vector of (-44.1889 mm, 17.5775 mm), then the object is 
>>> rotated according to what I expect but the new center is translated 
>>> to location (156.93 mm , 143.67 mm).
>>> If I apply the equations then the new center will be at (139.24 mm , 
>>> 193.8 mm).
>>>
>>>
>>> Again I have to be doing something wrong.
>>>
>>> Thanks for your help,
>>>
>>> Lucas
>>>
>>>
>>>
>>>> What are the coordinates of the center of the object ?
>>>> What is the translation that you are applyng ?
>>>>
>>>>
>>>> TheCenteredAffineTransform transforms a point P into
>>>> a point P' by using the following expression
>>>>
>>>>
>>>>       P' =  R * ( P - C )   +   ( T + C )
>>>>
>>>> In dimension N: C is a N dimensional point with
>>>> the coordinates of the center of rotation, P is
>>>> the N dimensional point to be transformed, P' is
>>>> the resulting N dimensional point, T is the N
>>>> dimensional translation Vector.
>>>>
>>>>
>>>>  Regards,
>>>>
>>>>
>>>>
>>>>     Luis
>>>>
>>>>
>>>>
>>>> ----------------------
>>>> Lucas Lorenzo wrote:
>>>>
>>>>> Hi Luis,
>>>>> I'm selecting the spatial coordinates of the center of the object 
>>>>> I'm interested in.
>>>>> Lucas
>>>>> On Jul 16, 2004, at 5:06 PM, Luis Ibanez wrote:
>>>>>
>>>>>> Hi Lucas,
>>>>>>
>>>>>>
>>>>>> What center of rotation did you selected ?
>>>>>>
>>>>>>  Luis
>>>>>>
>>>>>>
>>>>>> ---------------------
>>>>>> Lucas Lorenzo wrote:
>>>>>>
>>>>>>> Hi Luis,
>>>>>>> I've been running some tests so as to understand a little bit 
>>>>>>> better what's this transform doing and it is clear to me now that 
>>>>>>> it is applying the translation first and then it is rotating the 
>>>>>>> translated image with respect to the specified center of rotation.
>>>>>>> My understanding is that it should perform these operations but 
>>>>>>> in reverse order.
>>>>>>> Please let me know if this is wrong.
>>>>>>> Thanks,
>>>>>>> Lucas
>>>>>>> On Jul 16, 2004, at 2:14 PM, Lucas Lorenzo wrote:
>>>>>>>
>>>>>>>> Hi Luis,
>>>>>>>>
>>>>>>>> thanks for your feedback.
>>>>>>>>
>>>>>>>> 1) Till now the way I was setting the parameters was using the 
>>>>>>>> m_Transform->SetParameters(m_TransformParameters);
>>>>>>>>
>>>>>>>> 2) I have a 2D image so my understanding is that I'm going to 
>>>>>>>> have 8 parameters for this transformation where the first 4 
>>>>>>>> parameters define the rotation, shear, and scaling; the next two 
>>>>>>>> define the center of rotation and the last two define the 
>>>>>>>> translation to be applied with respect to the center of rotation 
>>>>>>>> (after the image has been rotated).
>>>>>>>>
>>>>>>>> Please, let me know where am I making a mistake.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> Lucas
>>>>>>>>
>>>>>>>>
>>>>>>>> On Jul 16, 2004, at 1:17 PM, Luis Ibanez wrote:
>>>>>>>>
>>>>>>>>>
>>>>>>>>> Hi Lucas,
>>>>>>>>>
>>>>>>>>> It is likely that you are misinterpreting
>>>>>>>>> the encoding of the parameters in this
>>>>>>>>> transform.
>>>>>>>>>
>>>>>>>>> Please post the values of the parameters
>>>>>>>>> that you are providing, and post also
>>>>>>>>> what you are expecting to be the effect.
>>>>>>>>>
>>>>>>>>> Note that you have:
>>>>>>>>>
>>>>>>>>>     - Center of rotation
>>>>>>>>>     - Translation
>>>>>>>>>     - Offset
>>>>>>>>>     - Rotation matrix
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> When you use this transform you should only
>>>>>>>>> care about SetCenter(), SetTranlation() and
>>>>>>>>> Rotation. Never touch the Offset directly.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> A code snippet illustrating the calls that
>>>>>>>>> you are making on the transform will also
>>>>>>>>> be very useful....
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>  Thanks
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>    Luis
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ----------------------
>>>>>>>>> Lucas Lorenzo wrote:
>>>>>>>>>
>>>>>>>>>> Hi Gavin,
>>>>>>>>>> thanks a lot for your answer.
>>>>>>>>>> I'm setting the parameters using
>>>>>>>>>>     m_Transform->SetParameters(m_TransformParameters);
>>>>>>>>>> So, afterwards I'm adding
>>>>>>>>>>     m_Transform->ComputeOffset();
>>>>>>>>>> But still the results are not as expected (after rotation the 
>>>>>>>>>> object is  not been translated to the desired location). Is 
>>>>>>>>>> there anything wrong  in what I'm doing ?
>>>>>>>>>> Thanks,
>>>>>>>>>> Lucas
>>>>>>>>>> On Jul 15, 2004, at 10:07 PM, Gavin Baker wrote:
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Hi Lucas,
>>>>>>>>>>>
>>>>>>>>>>> On Thu, Jul 15, 2004 at 06:01:26PM -0600, Lucas Lorenzo wrote:
>>>>>>>>>>>
>>>>>>>>>>>> I'm trying to use a Centered Affine Transform. So first I'm 
>>>>>>>>>>>> taking a
>>>>>>>>>>>> look at the following example:
>>>>>>>>>>>>
>>>>>>>>>>>> Examples/Registration/ImageRegistration9.cxx.
>>>>>>>>>>>>
>>>>>>>>>>>> I'm a little bit confused on how to use the ComputeOffset() 
>>>>>>>>>>>> method
>>>>>>>>>>>> because I don't see where it is been used in this example 
>>>>>>>>>>>> and when
>>>>>>>>>>>> reading the online documentation my understanding is that it is
>>>>>>>>>>>> mandatory to use this particular method.
>>>>>>>>>>>>
>>>>>>>>>>>> Could anyone please help me to get a better understanding on 
>>>>>>>>>>>> this  issue
>>>>>>>>>>>> ?
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> When using the centered affine transform, there is an 
>>>>>>>>>>> implicit  translation
>>>>>>>>>>> due to the center.  The offset takes into account the affect 
>>>>>>>>>>> of any
>>>>>>>>>>> rotations you specify on this center, to give a new 
>>>>>>>>>>> translation.  The
>>>>>>>>>>> ComputeOffset() method recalcuates this offset (which need 
>>>>>>>>>>> only be done
>>>>>>>>>>> once), and needs to be updated before applying the transform.
>>>>>>>>>>>
>>>>>>>>>>> This was discussed a while ago:
>>>>>>>>>>>
>>>>>>>>>>>    
>>>>>>>>>>> http://public.kitware.com/pipermail/insight-users/2003-October/ 
>>>>>>>>>>> 005230.html
>>>>>>>>>>>    
>>>>>>>>>>> http://public.kitware.com/pipermail/insight-users/2003-October/ 
>>>>>>>>>>> 005272.html
>>>>>>>>>>>
>>>>>>>>>>>> From the comments at the top of ImageRegistration9.cxx (from 
>>>>>>>>>>>> the  Software
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Guide) show:
>>>>>>>>>>>
>>>>>>>>>>>   //                      Note that the final total offset of 
>>>>>>>>>>> the  transform
>>>>>>>>>>>   //  is to be computed as a combination of the shift due 
>>>>>>>>>>> rotation  plus the
>>>>>>>>>>>   //  explicit translation set on the transform.
>>>>>>>>>>>   //
>>>>>>>>>>>
>>>>>>>>>>> General usage would be:
>>>>>>>>>>>
>>>>>>>>>>>   xform->Translate( delta );
>>>>>>>>>>>   xform->Rotate( theta );
>>>>>>>>>>>   // ...
>>>>>>>>>>>   xform->ComputeOffset();
>>>>>>>>>>>
>>>>>>>>>>>   resample->Update();
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> ComputeOffset() is actually called explicitly in all the
>>>>>>>>>>> CenteredAffineTransform methods that affect the transform, 
>>>>>>>>>>> but  (obviously)
>>>>>>>>>>> not any AffineTransform methods.  It isn't called 
>>>>>>>>>>> automagically (after  each
>>>>>>>>>>> change) since it only needs to be done once, although it 
>>>>>>>>>>> probably  wouldn't
>>>>>>>>>>> hurt if it were.
>>>>>>>>>>>
>>>>>>>>>>>   :: Gavin
>>>>>>>>>>>
>>>>>>>>>>> -- 
>>>>>>>>>>> Gavin Baker                                      Complex 
>>>>>>>>>>> Systems Group
>>>>>>>>>>> http://www.cs.mu.oz.au/~gavinb             The University of 
>>>>>>>>>>> Melbourne
>>>>>>>>>>> _______________________________________________
>>>>>>>>>>> Insight-users mailing list
>>>>>>>>>>> Insight-users at itk.org
>>>>>>>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>>>>>>>
>>>>>>>>>> Lucas Lorenzo
>>>>>>>>>> University of Utah
>>>>>>>>>> Nora Eccles Harrison CardioVascular Research and Training 
>>>>>>>>>> Institute
>>>>>>>>>> Fellows Room
>>>>>>>>>> 95 South 2000 East
>>>>>>>>>> Salt Lake City, UT 84112-5000
>>>>>>>>>> e-mail:  lucas at cvrti.utah.edu
>>>>>>>>>> telephone: 801-587-9536
>>>>>>>>>> _______________________________________________
>>>>>>>>>> Insight-users mailing list
>>>>>>>>>> Insight-users at itk.org
>>>>>>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>> Lucas Lorenzo
>>>>>>>>
>>>>>>>> University of Utah
>>>>>>>> Nora Eccles Harrison CardioVascular Research and Training Institute
>>>>>>>> Fellows Room
>>>>>>>> 95 South 2000 East
>>>>>>>> Salt Lake City, UT 84112-5000
>>>>>>>>
>>>>>>>> e-mail:  lucas at cvrti.utah.edu
>>>>>>>> telephone: 801-587-9536
>>>>>>>>
>>>>>>>>
>>>>>>> Lucas Lorenzo
>>>>>>> University of Utah
>>>>>>> Nora Eccles Harrison CardioVascular Research and Training Institute
>>>>>>> Fellows Room
>>>>>>> 95 South 2000 East
>>>>>>> Salt Lake City, UT 84112-5000
>>>>>>> e-mail:  lucas at cvrti.utah.edu
>>>>>>> telephone: 801-587-9536
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> Lucas Lorenzo
>>>>> University of Utah
>>>>> Nora Eccles Harrison CardioVascular Research and Training Institute
>>>>> Fellows Room
>>>>> 95 South 2000 East
>>>>> Salt Lake City, UT 84112-5000
>>>>> e-mail:  lucas at cvrti.utah.edu
>>>>> telephone: 801-587-9536
>>>>> _______________________________________________
>>>>> Insight-users mailing list
>>>>> Insight-users at itk.org
>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Insight-users mailing list
>>>> Insight-users at itk.org
>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>
>>> Lucas Lorenzo
>>>
>>> University of Utah
>>> Nora Eccles Harrison CardioVascular Research and Training Institute
>>> Fellows Room
>>> 95 South 2000 East
>>> Salt Lake City, UT 84112-5000
>>>
>>> e-mail:  lucas at cvrti.utah.edu
>>> telephone: 801-587-9536
>>>
>>>
>>
>>
>>
> 
> 





More information about the Insight-users mailing list