[Insight-users] transform an image problem
Vincent Magnotta
vincent-magnotta at uiowa.edu
Tue Sep 28 09:27:17 EDT 2010
Moti,
The number one reason for this type of error is not correctly handling the
origin and orientation in the images. Just quickly looking at the code, you
should also set the direction of the output image.
Vince
On 9/28/10 8:22 AM, "Moti Freiman" <freiman at cs.huji.ac.il> wrote:
> Hi All,
> I have an affine transformation that I produced using the ICP
> algorithm as implemented in VTK.
> Now I want to transfer the original moving image to the coordinates of
> the fixed one.
>
> I wrote a simple ITK based application, that read the images and the
> transform, and apply the trasnform to the moving image.
> However, It seems that I got an empty image (with default value),
> although the transformation of the surfaces using VTK works well.
> I tested the transformation by transforming several points using both
> ITK transform and the VTK transform, and the points transffered
> indentically.
> Does any one has an idea, some expirience with that problem.
>
> The code is attached bellow
> Best,
> Moti
>
>
>
>
> --------------------------------- ITK based affine image
> transformation -------------------------------------------
>
> // declare the affine transfrom
> typedef itk::AffineTransform <double,Dimension> itkAffineTransformType;
> itkAffineTransformType::Pointer trans = itkAffineTransformType::New();
> trans->SetIdentity();
>
> // read transform params from file
> std::fstream transFile;
> transFile.open (inputReferenceToPatientTransformFileName.c_str(),
> std::ios::in);
> int numOfElements = Dimension*Dimension;
>
> itkAffineTransformType::MatrixType matrix;
> itkTranslationTransformType::OutputVectorType translation;
>
> for (int i=0;i<Dimension;++i)
> {
> for (int j=0;j<Dimension;++j)
> {
> transFile >> matrix(i,j);
> }
> }
> dout << "end to read matrix" << std::endl;
> for (int i=0;i<Dimension;++i)
> {
> transFile >> translation[i];
> translation[i] = -translation[i];
>
> }
>
> transFile.close();
>
>
>
> trans->SetMatrix( matrix );
> trans->SetOffset(translation);
>
> // transform some point for testing purpose
> dout << trans << std::endl;
> itkAffineTransformType::InputPointType inPoint;
> inPoint[0] = 1; inPoint[1] = 1; inPoint[2] = 1;
> itkAffineTransformType::OutputPointType outPoint =
> trans->TransformPoint(inPoint);
> dout << outPoint[0] << ", " << outPoint[1] << ", " << outPoint[2] <<
> std::endl;
>
>
> // resample the moving image
> typedef itk::ResampleImageFilter< LabelsImageType,
> LabelsImageType > ResampleFilterType;
> ResampleFilterType::Pointer resampler = ResampleFilterType::New();
>
>
>
> typedef itk::NearestNeighborInterpolateImageFunction<LabelsImageType,
> double> InterpolatorType;
> InterpolatorType::Pointer interpolator = InterpolatorType::New();
> resampler->SetInterpolator( interpolator );
> resampler->SetTransform( trans );
> resampler->SetDefaultPixelValue(100);
> resampler->SetOutputSpacing( fixedImage );
> resampler->SetSize( fixedImage->GetLargestPossibleRegion().GetSize() );
> resampler->SetOutputOrigin( fixedImage->GetOrigin());
> resampler->SetInput (movingImage);
>
>
> resampler->Update();
>
>
> ------------------------------------------ end of code
> --------------------------------------------------------------
----------------------
Associate Professor
Department of Radiology
0453-D JCP
200 Hawkins Drive
Iowa City, IA 52242
E-mail: vincent-magnotta at uiowa.edu
Phone: 319-356-8255 Fax: 319-353-6275
Website: http://www.radiology.uiowa.edu
More information about the Insight-users
mailing list