[Insight-users] transform an image problem

Moti Freiman freiman at cs.huji.ac.il
Tue Sep 28 09:22:55 EDT 2010


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
--------------------------------------------------------------

-- 
__
Moti Freiman, Postdoctoral Associate,
Harvard Medical School.
Research Fellow,
Computational Radiology Laboratory.
Dept. of Radiology, Children's hospital,
300 Longwood Ave. Boston, MA 02115.

Lab website: http://crl.med.harvard.edu


More information about the Insight-users mailing list