Create Vector Image From Scalar Images#

Synopsis#

Create a vector image from a collection of scalar images.

Results#

Code#

C++#

#include "itkImage.h"
#include "itkComposeImageFilter.h"
#include "itkVectorImage.h"

namespace
{
using VectorImageType = itk::VectorImage<unsigned char, 2>;
using ScalarImageType = itk::Image<unsigned char, 2>;
} // namespace

static void
CreateImage(ScalarImageType::Pointer image);

int
main()
{
  auto image0 = ScalarImageType::New();
  CreateImage(image0);

  auto image1 = ScalarImageType::New();
  CreateImage(image1);

  auto image2 = ScalarImageType::New();
  CreateImage(image2);

  using ImageToVectorImageFilterType = itk::ComposeImageFilter<ScalarImageType>;
  auto imageToVectorImageFilter = ImageToVectorImageFilterType::New();
  imageToVectorImageFilter->SetInput(0, image0);
  imageToVectorImageFilter->SetInput(1, image1);
  imageToVectorImageFilter->SetInput(2, image2);
  imageToVectorImageFilter->Update();

  VectorImageType::Pointer vectorImage = imageToVectorImageFilter->GetOutput();

  return EXIT_SUCCESS;
}

void
CreateImage(ScalarImageType::Pointer image)
{
  ScalarImageType::IndexType start;
  start.Fill(0);

  ScalarImageType::SizeType size;
  size.Fill(100);

  ScalarImageType::RegionType region(start, size);

  image->SetRegions(region);
  image->Allocate();
  image->FillBuffer(0);
}

Classes demonstrated#

template<typename TInputImage, typename TOutputImage = VectorImage<typename TInputImage::PixelType, TInputImage::ImageDimension>>
class ComposeImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>

ComposeImageFilter combine several scalar images into a multicomponent image.

ComposeImageFilter combine several scalar images into an itk::Image of vector pixel (itk::Vector, itk::RGBPixel, …), of std::complex pixel, or in an itk::VectorImage.

Inputs and Usage

filter->SetInput( 0, image0 );
filter->SetInput( 1, image1 );
...
filter->Update();
itk::VectorImage< PixelType, dimension >::Pointer = filter->GetOutput();
All input images are expected to have the same template parameters and have the same size and origin.

See

VectorImage

See

VectorIndexSelectionCastImageFilter

ITK Sphinx Examples:

See itk::ComposeImageFilter for additional documentation.