I am using RegionOfInterestImageFilter and want to preserve the indices of the original image in the resampled image. The default seems to be that the sampled region starts at (0,0,0). I have tried
giving the same region to the input and output of the filter, but the indices still starts at (0,0,0). How do I get the filter to keep the original indices?
The ExtractImageFilter should preserve the original index and origin.
Wow! That was fast! It worked! Thanks very much!
output = roiFilter->GetOutput();
ExtractImageFilter seems to work… I can see the same pixel value at the same index for its input and output. My problem now is that I take the output and feed it to a ResampleImageFilter, using the same region parameters (and keeping the spacing the same for now). The regions all seem to match up, but the ResampleImageFilter doesn’t show the data at that same index, just the default pixel value.
Problem solved with the ResampleImageFilter. I needed to explicitly set the origin and direction of the filter output.
Sharing your final code fragment might help someone in the future.
While incomplete, here’s basically how I used ExtractImageFilterType to select a region and then ResampleFilterType to resample at twice the resolution.
//Create an extract image filter, whose output can be resampled
using ExtractImageFilterType =
m_extractImageFilter = ExtractImageFilterType::New();
//Create a resampler and interpolator at twice the resolution
unsigned short resamplingFactor = 2;
using ResampleFilterType =
for (unsigned int i = 0; i < inputImageNumberOfDimensions; ++i)
spacingResamplerOutput[i] = m_itkInputImage->GetSpacing()[i] / resamplingFactor;
startIndexResamplerOutput[i] = startIndexInputImage[i] * resamplingFactor;
sizeResamplerOutput[i] = regionInputImage.GetSize()[i] * resamplingFactor;
m_resampler = ResampleFilterType::New();
using InterpolatorType =
m_interpolator = InterpolatorType::New();
//These last two lines didn't seem needed, but were what finally made it all work.
If you just want to resample and increase the size of the image by an integer factor you may be interesting int the ExpandImageFilter: