Translate a Vector Image#
Synopsis#
Translate a vector image.
Results#
Code#
C++#
#include "itkImage.h"
#include "itkTranslationTransform.h"
#include "itkImageFileReader.h"
#include "itkResampleImageFilter.h"
#include "itkCovariantVector.h"
#include "itkNumericTraits.h"
int
main()
{
using VectorType = itk::CovariantVector<double, 3>;
using VectorImageType = itk::Image<VectorType, 2>;
auto image = VectorImageType::New();
itk::Index<2> start;
start.Fill(0);
itk::Size<2> size;
size.Fill(10);
itk::ImageRegion<2> region(start, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(itk::NumericTraits<VectorType>::ZeroValue());
itk::TranslationTransform<double, 2>::Pointer transform = itk::TranslationTransform<double, 2>::New();
itk::TranslationTransform<double, 2>::OutputVectorType translation;
translation[0] = 10;
translation[1] = 20;
transform->Translate(translation);
using ResampleFilterType = itk::ResampleImageFilter<VectorImageType, VectorImageType>;
auto vectorResampleFilter = ResampleFilterType::New();
vectorResampleFilter->SetInput(image);
vectorResampleFilter->SetSize(image->GetLargestPossibleRegion().GetSize());
vectorResampleFilter->SetTransform(transform);
vectorResampleFilter->Update();
return EXIT_SUCCESS;
}
Classes demonstrated#
-
template<typename TParametersValueType = double, unsigned int NDimensions = 3>
class TranslationTransform : public itk::Transform<TParametersValueType, NDimensions, NDimensions> Translation transformation of a vector space (e.g. space coordinates)
The same functionality could be obtained by using the Affine transform, but with a large difference in performance.
- ITK Sphinx Examples: