[Insight-users] Using ResampleImageFilter and OutputOrigin to resample and spatially center two volumes.

Jan Margeta jmargeta at gmail.com
Mon May 16 12:30:15 EDT 2011


Hi all,

This is to follow up on my previous question on ResampleImageFilter where I
wanted to resample a volume
to new spacing, direction and size. I would like to be able to have the
resampled volumes aligned when visualized
(i.e. if I would do a checkerboard visualization, the edges would
correspond).

The default behaviour is that the images are aligned with their borders and
the extrapolated values (or null regions)
appear only on half of the sides. The alignement works perfectly.

However, I would now like to have the resulting image region be centered
with the original image so that the extrapolated
value regions are equal all both sides and also have the images intensity
values well aligned.

Therefore I would expect that when I appropriatelly change the OutputOrigin
in the resampler, the images will be
sampled and aligned properly and the volumes centered in space at the same
time.

What I get instead are two volumes that whose outlines are centered as I
would want, but the image intensity
values do not correspond anymore (checkerboard edges do not correspond at
all). What did I forget?
Or is there any better way?

Here is the piece of code:

    typedef itk::ResampleImageFilter< InputImageType, InputImageType >
ResampleFilterType;

*    // Calculate new origin to center the images *
*    ResampleFilterType::PointType oldOrigin =
inputReader->GetOutput()->GetOrigin();
    ResampleFilterType::PointType newOrigin; newOrigin.Fill(0);

    for(size_t i = 0; i < 3; ++i)
    {
        double oldPhysicalSize = inputSpacing[i]*inputSize[i];
        double newPhysicalSize = outputSpacing[i]*outputSize[i];

        newOrigin[i] = oldOrigin[i] +
            0.5*(outputSpacing[i] - inputSpacing[i] +
                 oldPhysicalSize - newPhysicalSize);

    }   *


    ResampleFilterType::Pointer resampler = ResampleFilterType::New();
    resampler->SetInput( inputReader->GetOutput() );
    resampler->SetTransform( transform );
    resampler->SetInterpolator( interpolator );
  *  resampler->SetOutputOrigin( newOrigin );*
    resampler->SetOutputSpacing( outputSpacing );
    resampler->SetOutputDirection(
inputReader->GetOutput()->GetDirection());
    resampler->SetSize( outputSize );
    resampler->SetDefaultPixelValue(0);
    resampler->Update();

The reader is just an instance of itk::ImageSeriesReader<InputImageType>,
interpolation is linear, transformation is set to identity


Many thanks,

Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110516/c55a52ce/attachment.htm>


More information about the Insight-users mailing list