[Insight-users] Re: Re:Affine Transformation...

Luis Ibanez luis . ibanez at kitware . com
Thu, 08 Aug 2002 09:28:08 -0400


Hi cspl,

An Affine transform in 3D is defined by a 3x3 matrix M and
a 3x1 vector T. The transformation of a point is done by
the operation:

             P' = M . P + T

Your code looks fine. Just replacing the values of the matrix
and the offset should be enough to enable the transformation.

The values that you are currently setting in the matrix are
quite strange since you are putting the first row to zeros.
That will make the {x} coordinate of all the output points to
be zero, so the 3D image is squeezed in the plane x=0.

You may also want to take a look at the example in:
Insight/Testing/Code/BasicFilters/itkResampleImageFilterTest.cxx



   Luis




===========================================================================

cspl wrote:
> Dear Mr.Luis,
>  I am still facing the problem with SetMatrix() in 
> AffineTransformation.My application worked well when I set the matrix to 
> Identity and  Offset vector to zeros.But,I got two problems in getting 
> the output when matrix is set to other values.
> 
>  
> 
> 1.I coud not get the output when matrix is set to other values.(other 
> than identity).
> 2.I found that matrix is still 3x3.Because,when I tried to set values 
> which I have ,I could able to set only 3x3 i.e 9 values.
> 
>  
> 
> I am enclosing the code also.Please,help me regarding this.
> 
>  
> 
> typedef itk::AffineTransform<double, 3>TransformType ;
>  typedef itk::ResampleImageFilter<ImageType, ImageType, TransformType> 
> ResampleFilter;
> 
>  
> 
>  //typedef ResampleFilter::TransformType  TransformType  ;
>  ResampleFilter::Pointer Resample = ResampleFilter::New(); 
>  
>  TransformType::Pointer transform =  Resample->GetTransform();
> 
>  
> 
>  typedef  TransformType::MatrixType MatrixType;
>  typedef  TransformType::OffsetType  VectorType; 
>  VectorType vector2 = transform->GetOffset();
>  MatrixType matrix2 = transform->GetMatrix(); 
>  int i;
>  for (i = 0; i < 3; i++) {  
>   vector2[i] = 0.5;
>  }
> matrix2[0][0] = 0.0;
> matrix2[0][1] = 0.0;
> matrix2[0][2] = 0.0;
> matrix2[1][0] = 1.0;
> matrix2[1][1] = 0.0;
> matrix2[1][2] = 0.0;
> matrix2[2][0] = 1.0;
> matrix2[2][1] = 0.0;
> matrix2[2][2] = 0.0;
> 
>  
> 
> 
>  transform->SetOffset(vector2);
>  transform->SetMatrix(matrix2);
> 
>  
> 
>  
> 
>  
> 
>  itk::Size<3> size = 
>  {InputVolume->height,InputVolume->width,InputVolume->depth };
>  Resample->SetInput(InputImage);
>  Resample->SetSize(size);
>  double values[3];
>  values[0]=1.62;
>  values[1]=1.62;
>  values[2]=1.0;
>  Resample->SetOutputSpacing(values);
>  Resample->Update();
> 
>  
> 
> 
> Regards,
> CSPL 
>