int
main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0]
<< " inputImageFile outputImageFile_NearestNeighbor"
<< " outputImageFile_Linear " << std::endl;
return EXIT_FAILURE;
}
constexpr unsigned int Dimension = 2;
using PixelComponentType = unsigned char;
auto reader = ReaderType::New();
auto writerNearest = WriterType::New();
auto writerLinear = WriterType::New();
reader->SetFileName(argv[1]);
writerNearest->SetFileName(argv[2]);
writerLinear->SetFileName(argv[3]);
auto nearestFilter = FilterType::New();
auto linearFilter = FilterType::New();
using NearestInterpolatorType =
auto interpolatorNearest = NearestInterpolatorType::New();
using LinearInterpolatorType =
auto interpolatorLinear = LinearInterpolatorType::New();
nearestFilter->SetInterpolator(interpolatorNearest);
linearFilter->SetInterpolator(interpolatorLinear);
auto transform = TransformType::New();
nearestFilter->SetTransform(transform);
linearFilter->SetTransform(transform);
nearestFilter->SetDefaultPixelValue(defaultValue);
linearFilter->SetDefaultPixelValue(defaultValue);
ImageType::SpacingType spacing;
spacing[0] = .35;
spacing[1] = .35;
nearestFilter->SetOutputSpacing(spacing);
linearFilter->SetOutputSpacing(spacing);
ImageType::PointType origin;
origin[0] = 0.4;
origin[1] = 0.4;
nearestFilter->SetOutputOrigin(origin);
linearFilter->SetOutputOrigin(origin);
ImageType::DirectionType direction;
direction.SetIdentity();
nearestFilter->SetOutputDirection(direction);
linearFilter->SetOutputDirection(direction);
ImageType::SizeType size;
size[0] = 300;
size[1] = 300;
nearestFilter->SetSize(size);
linearFilter->SetSize(size);
nearestFilter->SetInput(reader->GetOutput());
linearFilter->SetInput(reader->GetOutput());
writerNearest->SetInput(nearestFilter->GetOutput());
writerLinear->SetInput(linearFilter->GetOutput());
try
{
writerNearest->Update();
}
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
}
try
{
writerLinear->Update();
}
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
}
return EXIT_SUCCESS;
}
Standard exception handling object.
Data source that reads image data from a single file.
Writes image data to a single file.
Templated n-dimensional image class.
Linearly interpolate an image at specified positions.
Nearest neighbor interpolation of a scalar image.
Represent Red, Green and Blue components for color images.
Resample an image via a coordinate transform.
constexpr TContainer MakeFilled(typename TContainer::const_reference value)