Hi all, <br><br>This is to follow up on my previous question on ResampleImageFilter where I wanted to resample a volume <br>to new spacing, direction and size. I would like to be able to have the resampled volumes aligned when visualized<br>
(i.e. if I would do a checkerboard visualization, the edges would correspond).<br><br>The default behaviour is that the images are aligned with their borders and the extrapolated values (or null regions) <br>appear only on half of the sides. The alignement works perfectly.<br>
<br>However, I would now like to have the resulting image region be centered with the original image so that the extrapolated <br>value regions are equal all both sides and also have the images intensity values well aligned.<br>
<br>Therefore I would expect that when I appropriatelly change the OutputOrigin in the resampler, the images will be <br>sampled and aligned properly and the volumes centered in space at the same time.<br><br>What I get instead are two volumes that whose outlines are centered as I would want, but the image intensity <br>
values do not correspond anymore (checkerboard edges do not correspond at all). What did I forget?<br>Or is there any better way?<br><br>Here is the piece of code:<br><div><br> typedef itk::ResampleImageFilter< InputImageType, InputImageType > ResampleFilterType;<br>
<br><b> // Calculate new origin to center the images </b><br><i> ResampleFilterType::PointType oldOrigin = inputReader->GetOutput()->GetOrigin(); <br> ResampleFilterType::PointType newOrigin; newOrigin.Fill(0);<br>
<br> for(size_t i = 0; i < 3; ++i) <br> { <br> double oldPhysicalSize = inputSpacing[i]*inputSize[i];<br> double newPhysicalSize = outputSpacing[i]*outputSize[i];<br><br> newOrigin[i] = oldOrigin[i] + <br>
0.5*(outputSpacing[i] - inputSpacing[i] + <br> oldPhysicalSize - newPhysicalSize);<br> <br> } </i><br><br><br> ResampleFilterType::Pointer resampler = ResampleFilterType::New();<br>
resampler->SetInput( inputReader->GetOutput() );<br>
resampler->SetTransform( transform );<br> resampler->SetInterpolator( interpolator ); <br> <b> resampler->SetOutputOrigin( newOrigin );</b><br> resampler->SetOutputSpacing( outputSpacing );<br>
resampler->SetOutputDirection( inputReader->GetOutput()->GetDirection());<br>
resampler->SetSize( outputSize );<br> resampler->SetDefaultPixelValue(0);<br> resampler->Update();<br><br>The reader is just an instance of itk::ImageSeriesReader<InputImageType>, interpolation is linear, transformation is set to identity<br>
<br><br>Many thanks,<br><font color="#888888"><br>Jan</font></div>