[Insight-users] to combine two affine transformations

Henry nyhenry at gmail.com
Sun Dec 9 16:58:10 EST 2007


Hi Luis,
Thanks for your reply. Yes, I use ResampleImageFilter.
I realize that ResampleImageFilter maps points from the fixed image
(output) to the moving (input) image. so when we apply Affine
Transform1 then Affine Transform2 to the input, the actual calculation
order would be based on output coordinate system, so the order is
reversed, i.e. Affine Transform2 then Affine Transform1. Is that the
case? I switch the two input
tfm file as input and get the result looks right.

Thanks,
Henry
On Dec 9, 2007 4:26 PM, Luis Ibanez <luis.ibanez at kitware.com> wrote:
>
> Hi Henry,
>
>
> Given two affine transforms:
>
>       Affine Transform1 = AF1 = ( M1, O1 )
>       Affine Transform2 = AF2 = ( M2, O2 )
>
>
> Applying the transform AF1 to a point P implies doing:
>
>                P' = M1 * P + O1
>
>
> Applying the transforms AF1 and AF2 in a sequence to
> a point P imply doing the following:
>
>
>                M2 * ( M1 * P + O1 ) + O2
>
> which is equivalent to
>
>        ( M2 * M1 ) * P + (M2 * O1) + O2
>
>
> So, the composition of AF1 and AF2 is AF3
>
>
>       AF3 = ( M3, O3 )
>
> where
>
>       M3 = M2 * M1
>
>       O3 = M2 * O1 + O2
>
>
>
> How are you applying the transformation AF1, AF2 to your image ?
> by using a Resample image filter  ?
>
> Notice that the ResampleImageFilter maps points from the fixed
> image to the moving (input) image. This tend to create confusion
> in some users.
>
>
>
> One thing that you may be doing wrong is the order in
> which you apply the transforms. If you use the wrong
> order you end up with a translation of
>
>        O3 = M1 * O2 + O1
>
> instead of the one above.
>
>
>
>
>
>     Regards,
>
>
>
>         Luis
>
>
>
> -------------
>
> Henry wrote:
> > Hi all,
> > I am confused by the results of combination of two transformations. I
> > need to apply affine transform1(Matrix1, Offset1) first and then
> > affine transform2 (Matrix2, Offset2).
> >
> > Should the result transform3(Matrix3, Offset3) be like
> >
> > Matrix3 = Matrix2*Matrix1
> > Matrix3 = Matrix2*Offset1 + Offset2 ?
> >
> > I apply the transform3 and compare the image with apply two separate
> > (transform1 and then transform2),  and found the rotations are the
> > same but the offset/translation of the two results are different.
> > Any idea why this happens?
> >
> > Thanks!!
> > Henry
> >
> > ~~~~~~~~~~~~~~~
> > //my program looks like this:
> >
> >   typedef itk::AffineTransform<double,3> AffineTransformType;
> >   AffineTransformType::Pointer affine = AffineTransformType::New();
> >   itk::TransformFileReader::Pointer transformreader1;
> >   itk::TransformFileReader::Pointer transformreader2;
> >   transformreader1 = itk::TransformFileReader::New();
> >   transformreader2 = itk::TransformFileReader::New();
> >   transformreader1->SetFileName( argv[1] );
> >   transformreader2->SetFileName( argv[2] );
> >
> >     transformreader1->Update();
> >     transformreader2->Update();
> >
> > //I read in two .tfm files and do the following:
> >
> >
> >       transform->SetMatrix( affine_read2->GetMatrix()*affine_read1->GetMatrix());
> >       transform->SetOffset(affine_read2->GetMatrix()*affine_read1->GetOffset()
> > +affine_read2->GetOffset());
> >
> >
> > //and then write the final results
> >
> >   itk::TransformFileWriter::Pointer writer;
> >   writer = itk::TransformFileWriter::New();
> >   writer->SetInput(transform);
> >   writer->SetFileName( argv[3] );
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> >
>


More information about the Insight-users mailing list