static void CreateImage(ImageType::Pointer image);
int main(int argc, char *argv[])
{
double factor = 2.0;
ImageType::Pointer input;
if(argc < 2)
{
input = ImageType::New();
CreateImage(input);
}
else
{
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();
input = reader->GetOutput();
if (argc > 2)
{
factor = atof(argv[2]);
}
}
std::cout << "Input size: " << inputSize << std::endl;
outputSize[0] = inputSize[0] * factor;
outputSize[1] = inputSize[1] * factor;
ImageType::SpacingType outputSpacing;
outputSpacing[0] = input->GetSpacing()[0] * (static_cast<double>(inputSize[0]) / static_cast<double>(outputSize[0]));
outputSpacing[1] = input->GetSpacing()[1] * (static_cast<double>(inputSize[1]) / static_cast<double>(outputSize[1]));
ResampleImageFilterType::Pointer resample = ResampleImageFilterType::New();
resample->SetInput(input);
resample->SetSize(outputSize);
resample->SetOutputSpacing(outputSpacing);
resample->SetTransform(TransformType::New());
resample->UpdateLargestPossibleRegion();
ImageType, double >;
NearestInterpolatorType::Pointer nnInterpolator =
NearestInterpolatorType::New();
ResampleImageFilterType::Pointer resampleNN =
ResampleImageFilterType::New();
resampleNN->SetInput(input);
resampleNN->SetSize(outputSize);
resampleNN->SetOutputSpacing(outputSpacing);
resampleNN->SetTransform(TransformType::New());
resampleNN->SetInterpolator(nnInterpolator);
resampleNN->UpdateLargestPossibleRegion();
ImageType::Pointer output = resample->GetOutput();
std::cout << "Output size: " << output->GetLargestPossibleRegion().GetSize() << std::endl;
true,
"Original");
true,
"Resampled");
true,
"Resampled NN");
return EXIT_SUCCESS;
}
void CreateImage(ImageType::Pointer image)
{
image->SetRegions(region);
image->Allocate();
image->FillBuffer( itk::NumericTraits< ImageType::PixelType >::Zero);
ImageType::PixelType pixel;
pixel.SetRed(200);
pixel.SetGreen(50);
pixel.SetBlue(50);
for(unsigned int r = 20; r < 80; r++)
{
for(unsigned int c = 30; c < 100; c++)
{
pixelIndex[0] = r;
pixelIndex[1] = c;
image->SetPixel(pixelIndex, pixel);
}
}
}