[Insight-users] applying previously saved transform to images

a.bongers at mediri.com a.bongers at mediri.com
Mon Dec 1 05:48:30 EST 2008


Hi, 

I'm having a problem with registration and transformation of an image with different spacings. 
What I would like to do is the following: 

Using the affine itk registration I have registered a 3D moving image with spacing (4,4,4) to a fixed image with spacing (1,1,4) and have saved the transformation to a file. This works well so far. The registerd images seem to fit well. 

In later stage I would like to apply the saved transform to the moving image but KEEPING THE SPACING OF THE MOVING IMAGE. (In effect I would like to apply a transform determined previously to another image, i.e. e.g. a mask image which I cannot register directly because it is lacking sufficient structures) 
--> 
So I simply tried to use the resample image filter but with the spacing from the moving image (4,4,4). 
When I do this, the resulting image after the application of the transform does not fit the fixed image but seems to be shifted by some amount. 

Since I do not really know how this comes about I hope anybody can help me... 
Does the Transform depend on image spacing somehow ??? Am I thinking wrongly ??? Is this a bug ??? How can I achieve a transform of the image without being dependent on the fixed image ? 


To illustrate what I am doing : Here is the code of the resampling function I wrote. 
The Problem is highlited in the source comments: 


my func is templated over the image type and trafo type and takes the trafo I previously read in from the itk transform file saved in the registration stage. 


template <class ImageType, class TrafoType> 
//typename ImageType::Pointer ResampleImage(typename ImageType::Pointer sourceImage, typename TrafoType::Pointer transform) 
typename ImageType::Pointer ResampleImage(typename ImageType::Pointer sourceImage, typename ImageType::Pointer targetImage, 
typename TrafoType::Pointer transform) 
{ 

typedef itk::LinearInterpolateImageFunction<ImageType,double> InterpolatorType; 
InterpolatorType::Pointer interp = InterpolatorType::New(); 
interp->SetInputImage(sourceImage); 

typedef itk::ResampleImageFilter<ImageType,ImageType> ResampleImageFilter; 
ResampleImageFilter::Pointer resample = ResampleImageFilter::New(); 
resample->SetInput(sourceImage); 

resample->SetTransform(transform); 
resample->SetInterpolator(interp); 

ImageType::IndexType index = {{0,0,0}}; 
resample->SetOutputStartIndex(index); 

// here I get a problem when I try to use the source images spacing 
// if I use the target's (i.e. fixed) image spacing everything works fine: 
ImageType::SizeType size = targetImage->GetLargestPossibleRegion().GetSize(); 
resample->SetSize(size); 
resample->SetOutputSpacing(targetImage->GetSpacing()); 
cout << targetImage->GetSpacing() << "spacing from target image !!!!!!!!!!!!!"; 
// this works ok 


// but if I use the source's (moving) image spacing it does not work --> the resuling transforemd image is then shifted 
//ImageType::SizeType size = sourceImage->GetLargestPossibleRegion().GetSize(); 
//resample->SetSize(size); 
//resample->SetOutputSpacing(sourceImage->GetSpacing()); 
//cout << sourceImage->GetSpacing() << "spacing from source image !!!!!!!!!!!!!"; 
// this works ok 

resample->SetOutputOrigin(sourceImage->GetOrigin()); 

resample->Update(); 
ImageType::Pointer outImage = resample->GetOutput(); 
outImage->SetDirection(sourceImage->GetDirection()); 

return outImage; 

} 




THAKS A LOT! 

Andre


More information about the Insight-users mailing list