[Insight-users] applying previously saved transform to images
Luis Ibanez
luis.ibanez at kitware.com
Tue Dec 2 16:11:11 EST 2008
Hi Andre,
What you are observing is perfectly normal,
and ... actually you are asking for it.
It is valid to resample the moving image by using an
spacing that is different from the Fixed image.
There is nothing wrong with that...
However,
you can't ask then for the resulting resampled image
to still fit the fixed image that you have, at least
not at the image grid level.
In practice what you have is not an image registration
problem, but an image visualization problem.
you are probably using a poor visualization tool that
does not take into account properly the spacing of the
fixed image and the resampled moving image.
Please give it a try to Slicer (www.slicer.org), this
is probably the only application out there that will
properly display two images of different spacing.
Under slicer, the Fixed image and the Resampled moving
image should appear overlapping correctly, (if the
registration actually succeeded...).
Please let us know if you have any questions.
Thanks
Luis
-----------------------------
a.bongers at mediri.com wrote:
> 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
> _______________________________________________
> 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