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?
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.
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 =
itk::ExtractImageFilter<InputImageType, InputImageType>;
ExtractImageFilterType::Pointer m_extractImageFilter;
m_extractImageFilter = ExtractImageFilterType::New();
m_extractImageFilter->SetInput(m_itkInputImage);
m_extractImageFilter->SetExtractionRegion(regionInputImage);
m_extractImageFilter->Update();
//Create a resampler and interpolator at twice the resolution
unsigned short resamplingFactor = 2;
using ResampleFilterType =
itk::ResampleImageFilter<InputImageType, InputImageType>;
ResampleFilterType::Pointer m_resampler;
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();
m_resampler->SetInput(m_extractImageFilter->GetOutput());
using InterpolatorType =
itk::LinearInterpolateImageFunction<InputImageType, double>;
InterpolatorType::Pointer m_interpolator;
m_interpolator = InterpolatorType::New();
m_resampler->SetInterpolator(m_interpolator);
m_resampler->SetOutputSpacing(spacingResamplerOutput);
m_resampler->SetOutputStartIndex(startIndexResamplerOutput);
m_resampler->SetSize(sizeResamplerOutput);
//These last two lines didn't seem needed, but were what finally made it all work.
m_resampler->SetOutputOrigin(m_itkInputImage->GetOrigin());
m_resampler->SetOutputDirection(m_itkInputImage->GetDirection());
m_resampler->Update();